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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing dynamic text boxes..

Status
Not open for further replies.

Rebies

Programmer
Mar 7, 2002
58
0
0
US
I have searched high and low, and can't quite figure this out. Any help would be appreciated.

I have X number of text boxes on a page. It is always changing, but I do have the total number stored in a hidden text box titled 'loops'. The text boxes are named in the fashion of:

quant1
quant2
quant3

and so forth. I am trying to create a loop that will read the contents of each text box and check for a match with 'xyz'. Note: The following does not work, but is what I am trying to do:

<script language=&quot;JavaScript&quot;>
<!--
function check_form(f) {
for (i=1; i<document.daForm.loops.value; i++) {
if (document.daForm.quant' + i + '.value == 'xyz') {
alert('I wish the above would work');
}
}
}
-->
</script>


Andrew
 
Hello Andrew:

I hope this helps:

Rename your text boxes to the same name,let's say quant1.If you do that, a new array of text boxes is created.The array name would be quant1,and you can easily locate wich text box contain the value &quot;xyz&quot;.

Here is the example:

<html>
<head>
<script language=&quot;JavaScript&quot;>
function CheckValue()
{
for(i=0;i<document.myform.quant1.length;i++)
{
if(document.myform.quant1.value=='xyz')
alert('Match found in text box number '+eval(i+1));
}
}
</script>
</head>
<body>
<form name=&quot;myform&quot;>
<input type=&quot;text&quot; name=&quot;quant1&quot; value=&quot;Value1&quot;>
<br>
<input type=&quot;text&quot; name=&quot;quant1&quot; value=&quot;Value2&quot;>
<br>
<input type=&quot;text&quot; name=&quot;quant1&quot; value=&quot;Value3&quot;>
<br>
<input type=&quot;text&quot; name=&quot;quant1&quot; value=&quot;xyz&quot;>
<br>
<input type=&quot;text&quot; name=&quot;quant1&quot; value=&quot;Value5&quot;>
<br>
<input type=&quot;button&quot; name=&quot;mybutton&quot; value=&quot;Check Values&quot; onclick=&quot;CheckValue()&quot;>
</form>
</body>
</html>

I hope this helps.

Kindest Regards

Alex
 
\\ also
function show_val(where, who)
{
a = document.getElementById(where).getElementsByTagName(who);
for(b=0;b<=a.length;b++)
{
alert(&quot;alert number &quot; + b + &quot; : &quot; + a.value);
}
}

\\ later
<form id=&quot;form_name&quot; ...>
\\\ call the function like this example
<a href=&quot;javascript:show_val('form_name', 'input')&quot;>test</a>
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Well, both could work, but the fact is I can't change the names of the text boxes to the same thing because of Cold Fusion processing at the other side. (Things would get really confusing - not knowing which text box belongs to which set of data)

Also, I have multiple hidden fields and checkboxes, so the 2nd idea wouldn't work without some heavy workarounds.

Is there a way in JavaScript (as I do it in ColdFusion) to dynamically say:

#evaluate(&quot;quant#i#&quot;)#

This returns the information stored in quant1, quant2 (ow whatever i currently is).

Thanks for your help. I'm sure there is a way of referencing this information, just can't find out the proper way.

Andrew
 
<script language=&quot;JavaScript&quot;>
<!--
function check_form(f) {
for (i=1; i<document.daForm.loops.value; i++) {
if (document.daForm[&quot;quant&quot; + i + &quot;].value == 'xyz') {
alert('I wish the above would work');
}
}
}
-->
</script>
--BB
 
Sorry BB101:

I meant to respond saying thanks. That is exactly what I was looking for and it makes me so happy knowing I wasn't crazy in looking for that one method of doing it.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top