Forum Moderators: open

Message Too Old, No Replies

How to correct my javascript error

Getting error in onchange event method

         

srins

7:41 pm on Aug 13, 2006 (gmt 0)

10+ Year Member



Hi,

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

MisYu

7:54 am on Aug 14, 2006 (gmt 0)

10+ Year Member



First of all, close your <option> tags.
Second of all, instead of getting your pulldown's value in weird way, modify it just to:

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;

Rambo Tribble

10:31 pm on Aug 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suspect the problem results from the line:
var selectBox = document.forms[0].select;

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.