IreneLing Posted September 29, 2011 Share Posted September 29, 2011 Really thanks to freelance84 help for my previous post , and again , I have a small problem . I tried to make a function that , once a textbox is hidden , the value will automatically reset to 0. function resettextbox(id) { var firsthiddenbox = document.getElementById(id); if(firsthiddenbox.style.display = 'none') { firsthiddenbox.value = 0; } <input type="text" id="nameBox" onkeyup="nameCheck('nameBox','FIRST NAME',hiddenBox');resettextbox(hiddenBox)"/> hmm...it not really works of course , is there anything I need to change ? Thanks for every reply . Link to comment https://forums.phpfreaks.com/topic/248088-reset-textbox-value-once-its-hidden/ Share on other sites More sharing options...
MarPlo Posted September 29, 2011 Share Posted September 29, 2011 Hi, I'm not sure if it works, but try 2 "=" in if() statement, like this: if(firsthiddenbox.style.display == 'none') Link to comment https://forums.phpfreaks.com/topic/248088-reset-textbox-value-once-its-hidden/#findComment-1274035 Share on other sites More sharing options...
freelance84 Posted September 29, 2011 Share Posted September 29, 2011 if(x == y) is like saying if x is the same as y if(x = y) is like saying x equals y Also, you could write it into the function too. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> /*display hidden box if first name exists*/ function nameCheck(id,key,id2){ var nameCheck = document.getElementById(id).value; if(nameCheck.search(key) > -1 ){ document.getElementById(id2).style.display = 'inline'; } else{ document.getElementById(id2).style.display = 'none'; if(document.getElementById(id2).style.display == 'none'){ document.getElementById(id2).value = ''; } } } function alertTextAreaContent(){ var taVal = document.getElementById('hiddenBox').value; alert(taVal); } </script> </head> <body > <input type="text" id="nameBox" onkeyup="nameCheck('nameBox','FIRST NAME','hiddenBox')"/><br/> <textarea id="hiddenBox" style="display:none;"> rty erty rty rtyh</textarea> <input type="button" value="Test textarea content" onclick="alertTextAreaContent();"/> </body> </html> Link to comment https://forums.phpfreaks.com/topic/248088-reset-textbox-value-once-its-hidden/#findComment-1274043 Share on other sites More sharing options...
IreneLing Posted October 1, 2011 Author Share Posted October 1, 2011 I'm so sorry for my late response , and thanks to the reply MarPlo and freelance84. The code works very well , really thanks freelance84 , you helped me a lot . Have a nice day . Link to comment https://forums.phpfreaks.com/topic/248088-reset-textbox-value-once-its-hidden/#findComment-1274654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.