Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 350
Ganesh Bhosle Avatar asked Aug 22 '13 10:08

Ganesh Bhosle


1 Answers

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());
like image 145
Rituraj ratan Avatar answered Oct 18 '22 17:10

Rituraj ratan