Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing back and forth

Status
Not open for further replies.

clinel

Technical User
Joined
Mar 27, 2004
Messages
3
Location
US
I have a form with an array of text boxes and hidden fields (input1, input2,... hdnReason1, hdnReason2,...) If the value of the text field is below a certain value, I want to call a popup for the user to enter a reason. I then want to pass that reasons back to the correct hidden field on the parent page. I think that I can loop through text fields and call the popup; how do I get the value back from the popup to the correct hidden field. I have just enough knowledge of js to be dangerous. A brief overview of what is happening would help take the edge off. Thanks in advance!!
 
looping through all elements, checking types, and populating another field based on the field name (UNTESTED!)...

Code:
function blah(f) {
    var e = f.elements;
    var minVal = 10;

    for ( var i = 0; i < e.length; i++ ) {
        if ( e[i].type == "text" ) {
            if ( parseInt( e[i].value ) < minVal ) {
                var reason = prompt("Give a reason...", "");
                // i'm not sure if this next line will work
                var fieldindex = parseInt( e[i].name );
                e['hdnReason' + fieldindex].value = reason;
            }
        }
    }
}



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I always frown against popups... I would suggest doing it this way:


Code:
<head>
<title>Reason</title>
<script type="text/javascript">
	function checkvalue(reasonid,valuemin) {
		str = document.getElementById('fvalue' + reasonid).value;					// grab value of textfield
		if (str < valuemin  ) {														// check if lower less than accepted value
			document.getElementById('reason' + reasonid).style.display="";			// show reason field
		 } else {
			 document.getElementById('reason' + reasonid).style.display="none";		// hide reason field they change their value
		}
	}
</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0">
  <tr>
    <td height="27">Value 
    <input name="frmValue1" type="text" size="5" id="fvalue1" onkeyup="checkvalue('1','5');"/></td>
  </tr>
 <tbody id="reason1" style="display:none;">
  <tr>
    <td height="27">Reason why value is not high enough: </td>
  </tr>
  <tr>
    <td><input type="text" name="frmReason1"/></td>
  </tr>
 </tbody>
</table>
</body>
</html>

Army : Combat Engineer : 21B

 
You beat me to it... clfava! :D hey can you take a look at my other post... thread216-1266835 i am trying to figure out why ajax makes more than 1 request to the page... am i do something wrong?
 
Thanks snowboardr,
I agree with you concerning the popups, but the input screen has no more room for addtional inputs on the main page. The app is used to gather production data for our plant. In addition, I going to use radio buttons to classify the reasons (to make querying by type easier) as well as collect the specific comments. I'm just not sure how to get the popup to return the values to the correct hidden fields associated with the text field. I think that I can do the error checking and then call the popup, I just don't how to tell the popup to post the value back to a specific hidden field. (i.e. txtTime1 < target, post rdoReason.value back to hdnReason1, post txtComment back to hdnComment1)
 
Well if you take a look at cflava's code above, thats exactly what happens, when you click the main button it checks all your values and does a javascript alert message to enter a reason, then stores the reason in a hidden field...

Jason

Army : Combat Engineer : 21B

 
there is no more room? that's not the best excuse i've heard. if you need to capture data elements, then you need to include them in your page.

the method i gave you is a work-around. with javascript disabled, it will do nothing.

the hands-down best method is to either include the fields on the page initially, or process the submitted values server-side, then show another form to capture any reasons, if necessary.

popping up a window for each field below a min value will be cloogy, annoying, and bug-prone.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 

You could always create a (floating) div in the page that you show/hide based on user selection (doesn't have to float, it can be inline and expand the page) - that way you can have the fields within the form for posting, whilst 'saving' space by showing just one of the divs at a time. It also makes it less clunky (external window popups are horrid for the user in most cases), and easier to develop (you just need the code to show / hide div elements in js, which is quite simple). You can also make it reasonably accessible if you use JS to hide the elements (e.g. document.write the inline style) upon page load (so if js is disabled, it will simply display all the elements of the form).

There are other ways, but sometimes the simplest (just creating a bigger form) might be a better experience for the users.. try asking them what they would prefer - a longer form, external window popups, or in page floating divs - after all, they will be the ones using it.



A smile is worth a thousand kind words. So smile, it's easy! :-)
 
I have gave up the popup path.. I have set up a results page that returns all records that have to have reasons for the variance (radio buttons to classify.. text box for comments).
I want to do error checking on the form before they posting the page. I have used code to check for a selection on radio button when the name is static
(for (var i = 0; i < doc1.rdoReason.length; i++) {
if (doc1.rdoReason.checked) {
checkedIdx = i;
}
if (checkedIdx == -1) {
alert('Please select a reason!');
return false;
}
})
The thing is the names are dynamic(could be up to 12 rows) and are dependent on the number of records that are found to be exception that need additional info. They are named rdoReason1 - rdoReason12 an txtComments1 - txtComments12 depending on the number of records. The question is how do I loop through the radio buttons/text boxes and check to see if each row has a selection and comments?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top