why can't recognize index in hidden variable

J

john woo

Hi

I got a question in a form. that's:

<TABLE WIDTH="100%" BORDER=0><TD align="Left" width="19%" >
<select name="DEPARTMENT" SIZE ="1" style="width:200px;"
onChange="Change()">
<option value="0"> &lt;ALL&gt
<option value="1000012" >Food Sales
....
</select>
</TD>

<FORM name="InputForm" id="InputForm" method="post" action="url">
<INPUT TYPE="HIDDEN" NAME="DEPARTMENT" VALUE="">

function Change()
{
var selIndex = document.InputForm.DEPARTMENT.selectedIndex;
alert("****" + selIndex + "***");
var selValue =
document.InputForm.DEPARTMENT.options[selIndex].value;


the question is, why the pop up message always says ***undefined***
whenever a change to the selection?

It should indentify the selected index, right?

Can any one point it out?
 
J

Joakim Braun

john woo said:
Hi

I got a question in a form. that's:

<TABLE WIDTH="100%" BORDER=0><TD align="Left" width="19%" >
<select name="DEPARTMENT" SIZE ="1" style="width:200px;"
onChange="Change()">
<option value="0"> &lt;ALL&gt
<option value="1000012" >Food Sales
...
</select>
</TD>

<FORM name="InputForm" id="InputForm" method="post" action="url">
<INPUT TYPE="HIDDEN" NAME="DEPARTMENT" VALUE="">

function Change()
{
var selIndex = document.InputForm.DEPARTMENT.selectedIndex;
alert("****" + selIndex + "***");
var selValue =
document.InputForm.DEPARTMENT.options[selIndex].value;


the question is, why the pop up message always says ***undefined***
whenever a change to the selection?

It should indentify the selected index, right?

No, it shouldn't. A hidden field has no selected index. And the hidden field
of the form "InputForm" is what your code accesses.
 
J

john woo

Thanks lots.

one more question, if the form in above code is included from others,
how can I overwrite the accessiblity of the variable in that form?
 
M

Mick White

john woo wrote:
[..]
<select name="DEPARTMENT" SIZE ="1" style="width:200px;"
onChange="Change()">
<option value="0"> &lt;ALL&gt
<option value="1000012" >Food Sales
...
</select>
</TD>

<FORM name="InputForm" id="InputForm" method="post" action="url">
<INPUT TYPE="HIDDEN" NAME="DEPARTMENT" VALUE="">

function Change()
{
var selIndex = document.InputForm.DEPARTMENT.selectedIndex;
alert("****" + selIndex + "***");
var selValue =
document.InputForm.DEPARTMENT.options[selIndex].value;


the question is, why the pop up message always says ***undefined***
whenever a change to the selection?

It should indentify the selected index, right?

Can any one point it out?

Your select object appears to be outside of your form, and your hidden
field object should have a unique name.

Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top