javascript - Hide Input Field and Still Take User Input -
i working on project need hidden input field take user input.
i have javascript in place focus on input field. when div visible can see typing. when hide div type , make div visible again not see change. how can make when div hidden, still take user input? really, if there way besides hiding, great.
<html> <body> <div id="diva"> <input name="geta" id="geta" type="text" onkeypress="javascript:geta.focus();" onkeyup="javascript:geta.focus();" onblur="javascript:geta.focus();" onchange="javascript:geta.focus();" /> </div> <button onclick="javascript:change();">show/hide div</button> <script language="javascript" type="text/javascript"> <!-- function change() { var div = document.getelementbyid('diva'); if (div.style.display !== 'none') { div.style.display = 'none'; } else { div.style.display = 'block'; } }; geta.focus(); // --> </script> </body> </html>
fixed copy using jeffman's idea:
<html> <head> <style> input { position: absolute; left: -999em; } </style> </head> <body> <input name="geta" id="geta" type="text" onkeypress="javascript:geta.focus();" onkeyup="javascript:geta.focus();" onblur="javascript:geta.focus();" onchange="javascript:geta.focus();" /> <button onclick="javascript:show();">show</button><button onclick="javascript:hide();">hide</button> <script language="javascript" type="text/javascript"> <!-- function hide() { document.getelementbyid('geta').style.position = 'absolute'; document.getelementbyid('geta').style.left = '-999em'; } function show() { document.getelementbyid('geta').style.position = 'absolute'; document.getelementbyid('geta').style.left = '10em'; } geta.focus(); // --> </script> </body> </html>
are trying make user input captured hidden input field?
if can add onkeyup trigger document, , every keyup, modify hidden input field.
otherwise, once have hidden element loses focus.
simple example:
i don't know if using jquery, here native, simple solution, put in head tag
document.onkeyup = function(e) { var input = document.getelementbyid('myinput'); if (input.style.display == 'none') { input.value += string.fromcharcode(e.keycode || e.which); } };
Comments
Post a Comment