Forum Moderators: open
How to get user selected option in select menu option.
I tried something as
<select name="Testcase_Version" onchange="gover()">
<option value="1.2">1.2
<option value="1.3">1.3
<option value="1.4">1.4
</select>
if user select 1.3 option,i need to pass this to my cgi file as 1.3.
and in script i have given
function gover()
{
box = document.forms[0].display;
var selectBox = document.forms[0].select;
destination = selectBox.options[selectBox.selectedIndex].value
url="hiView.cgi?op=testcase_change_version_type&com=comand1&Testcase_Version=destination";
location.href = url;
}
In cgi file i will use op as parameter to check for particular function and need to pass the selected option to that function.
But i am getting error as i do this above method.
error as
"option is not null or not an object"
How to modify my script to correct my error.
Thanks,
Srins
onchange="javascript:gover(this.value);"
Declaration of gover function change to, in example: function gover(param)
Delete all stuff except for 'url' line, and change this line to:
var url="hiView.cgi?op=testcase_change_version_type&com=comand1&Testcase_Version=".concat(param);
document.location.href = url;
I imagine what you want is:
var selectBox = document.forms[0].Testcase_Version;
In the line:
onchange="javascript:gover(this.value);"
the javascript: pseudo-URL has no effect; it is only intended to be used as an href value to call the JavaScript interpreter through a link.
Document.location has been deprecated, replaced by window.location. It is common to use location.href, as the interpreter will assume the current window (self, this) is the target.