ClassCastException
ClassCastException

Reputation: 1473

innerHTML works in Firefox but not in Chrome

If we execute below code in Firefox 23, both alert boxes show correct value. When I execute the same in Chrome 28, second alert shows blank window.

HTML

<input type="hidden" id="mappingIDinput"/>

JS

alert(mappingId);
document.getElementById("mappingIDinput").innerHTML=mappingId;  
alert(document.getElementById("mappingIDinput").innerHTML);

How can I save & retrieve value in hidden input field which works across browsers(ignore IE if required).

Upvotes: 6

Views: 11996

Answers (3)

Roy M J
Roy M J

Reputation: 6938

Use .val() for all inputs. Inner html is for etc.

$("#mappingIDinput").val(mappingId);

Cheers

Upvotes: 0

Manu M
Manu M

Reputation: 1064

You cant use innerHTML to set value for an input tag but use value or val() in jquery.

Upvotes: 0

Rituraj ratan
Rituraj ratan

Reputation: 10388

for input field use value not html to get their value

IN JAVASCRIPT

SET

document.getElementById("mappingIDinput").value="abc";

GET

alert(document.getElementById("mappingIDinput").value);

in jQuery

SET

$("#mappingIDinput").val("abc");

GET

 alert($("#mappingIDinput").val());

Upvotes: 3

Related Questions