...

View Full Version : drop down form



Paulie20
06-19-2009, 02:30 PM
Hi

Very new to javascript. Cannot get past this problem and will be grateful for some help on what I know is simple for an experienced js person.

Here is my code. I want the page to refresh when a new option is selected and the function called Results(xxx) to return xxx as the option selected from the form.

<td>
<script type="text/javascript">
<!--
passvar=getValues();
Results(passvar);

// -->
</script>

</td>
</tr>
</table>

<FORM name="FormDropDown">
<SELECT name="SelectGrade" onChange="document.location.reload (true)">>
<OPTION value="Womens">Womens</option>
<OPTION value="U17">Under 17s</option>
<OPTION value="First Grade">First Grade</option>
<OPTION value="Womens">Womens</option>
</SELECT>
</FORM>

</body>
</html>

Here is my script:

function getvalues(){
var dd = document.getElementById('FormDropDown');
getvalues = dd.options[dd.selectedIndex].text;
}

Philip M
06-19-2009, 04:55 PM
function getvalues(){
var dd = document.getElementById('FormDropDown');
getvalues = dd.options[dd.selectedIndex].text;
}

You are using the same name for a function and a variable. :(
And you are using document.getElementById('FormDropDown'); although the form has only a name, not an id. :(


Try this:-


<FORM name="FormDropDown">
<SELECT name="SelectGrade" onChange="getvalues(this); document.location.reload (true)">>
<OPTION value="Womens">Womens</option>
<OPTION value="U17">Under 17s</option>
<OPTION value="First Grade">First Grade</option>
<OPTION value="Womens">Womens</option> :confused::confused:
</SELECT>
</FORM>

<script type = "text/javascript">
var gv; // gv is declared here as a global variable available for use in other functions.
function getvalues(which) {
gv = which.options[which.selectedIndex].text;
alert (gv);
}

</script>


For some reason you have Womens in the option list twice.
Note that as you are using onchange() you will need to add something like
<option value = "">-Make a selection-</option>
as otherwise Womens will not trigger the script.

Why are you capturing the option text rather than the value?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum