开发者

How do to I send my select box value to javascript

I have a random amount of select boxes generated by javascript, all containing the same options. Now I wish to have a "master-selectbox" which sets the value for each and every one of them.

Currently I have <select id="changeKlas" onChange="javascript:changeClass(this.parentNode, getElementById(changeKlas))">

At the javascript I've gotten as far as to find each and every select box and I already know how to set the value but the value is not being send to javascript.

On each attempt I have made the getElementById(changeKlas) is null. 开发者_如何学Python How can I fix this so I can get the text and value of the selected textbox in the given select?


Try this.

<select id="changeKlas" onChange="changeClass(this)">

And in your JavaScript, this will be transformed to document.getElementById(changeKlas)


You need to quote the id: [...], document.getElementById('changeKlas') -- notice the single quote, double quote needs to be escaped because of the outer one from onChange. Also, notice that getElementById belongs to document


<select id="changeKlas" onChange="changeClass();">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="black">Black</option>
</select>

<script>
function changeClass()
{
 var changeKlas = document.getElementById('changeKlas').value;
alert(changeKlas);
}
</script>

// On change It will alert the SELECTED VALUE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜