...

View Full Version : What is the order of elements?



ScottInTexas
10-14-2003, 08:45 PM
I seem to have a standing problem with getting to elements through javascript.

In this episode I have two selects on a form. When the select changes I want to submit the form after setting the value of the important field to the value of the select. My problem is that I can't get to the form let alone the field on the form.



<Form name="SurvForm" action="survey.asp" method="Post" id="SurvForm" >
<select Size="1" name="ComSurv" onChange="DoSurvey(this)">
<option Selected value="Select" />--------- Select ---------
<%
While NOT RS.EOF
%><option value= <% =RS("JobNumber") %> /> <% = RS("SurveyName") %>
<% RS.MoveNext
Wend %>
</select>
<input type="hidden" value="" name="JobNo" />
</form>

Scripts

I am trying to get to the form that has the select as a child element.

function DoSurvey(which){
alert("Doing Survey. Getting " + which.value);
which.parent.form.jobNo.value=which.value;
which.parent.form.submit();
}


What is above is just the last WAG at what I am trying to get to.

Thanks for looking.

beetle
10-14-2003, 08:57 PM
All form elements have a built-in reference to the form to which they belong, which is stored as

element.form

So, in your function, the parent is wrong, just use

which.form.jobNo.value = which.options[which.selectedIndex].value;

ScottInTexas
10-15-2003, 12:22 PM
Thanks for your reply.

Since this is personal stuff and I'm at work now, I'll try your code when I get a chance later today and see what happens.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum