I tried to assign a new value into the hidden input and checkbox of an input form. It's working fine in Firefox but not in IE (I'm using IE 7). Does anyone know what is wrong with my code?
HTML:
<input type="hidden" id="msg" name="msg" value="" style="display:none"/> <input type="checkbox" name="sp" value="100" id="sp_100">
Javascript:
var Msg="abc"; document.getElementById('msg').value = Msg; document.getElementById('sp_100').checked = true;
HTML DOM Document getElementById() The getElementById() method returns an element with a specified value. The getElementById() method returns null if the element does not exist. The getElementById() method is one of the most common methods in the HTML DOM.
A commonly-used alternative to document. getElementById is using a jQuery selector which you read about more here.
For non-grouped elements, name and id should be same. In this case you gave name as 'sp' and id as 'sp_100'. Don't do that, do it like this:
HTML:
<input type="hidden" id="msg" name="msg" value="" style="display:none"/> <input type="checkbox" name="sp" value="100" id="sp">
Javascript:
var Msg="abc"; document.getElementById('msg').value = Msg; document.getElementById('sp').checked = true;
For more details
please visit : http://www.impressivewebs.com/avoiding-problems-with-javascript-getelementbyid-method-in-internet-explorer-7/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With