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

Dynamically refering to form fields

Status
Not open for further replies.

nero

Programmer
Sep 11, 2000
25
AU
I have a jsp form which dynamically populates a <select> with existing roles, the code then creates corresponding hidden fields to hold the values of the select options as I cannot store the name of the option in the options value.

what I'm trying to do here is onChange in the select, I simply want to output the value of the hidden field value corresponding to the option within the select.

I am currently getting an &quot;Expected ';'&quot; at the
var myVal = eval(&quot;document.myForm.&quot; + i + &quot;.value&quot;);
line every time this is executed.

Anyone have any ideas?

Thanks in advance.

The following is a snippet from my code:

function selectSalesOffice() {
for (i=0; i<document.myForm.EXISTINGROLES.length; i++) {
var myVal = eval(&quot;document.myForm.&quot; + i + &quot;.value&quot;);
alert(myVal);
}
}

<form name=myForm>
<SELECT name=EXISTINGROLES onChange=&quot;selectSalesOffice();&quot;>
<OPTION value=&quot;notSelected&quot;> Admin
<OPTION value=&quot;notSelected&quot; selected> User
<OPTION value=&quot;notSelected&quot;> Viewer
</SELECT>

<input type=hidden name=0 value=Admin>
<input type=hidden name=1 value=User>
<input type=hidden name=2 value=Viewer>

 
hi nero!!

Go thru this code it may solve problem still do u have problem let me know/explain clearly.

-ravikumar


<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

<P> </P>
<SCRIPT LANGUAGE=javascript>

function selectSalesOffice(val) {
var myVal=val;
alert(myVal);
}

</SCRIPT>


<form name=myForm>
<SELECT name=EXISTINGROLES onChange=&quot;selectSalesOffice(this.value);&quot;>
<OPTION value=&quot;0&quot;> Admin
<OPTION value=&quot;1&quot; selected> User
<OPTION value=&quot;2&quot;> Viewer
</SELECT>

<input type=hidden name=0 value=Admin>
<input type=hidden name=1 value=User>
<input type=hidden name=2 value=Viewer>
</BODY>
</HTML>
 
For some reason, javascript does not like having .value in an eval, but this will work:
Code:
    var myObj = eval(&quot;document.myForm.&quot; + i);
    var myVal = myObj.value;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks you guys.

It's all working now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top