Jump to content

Reset textbox value once it's hidden


IreneLing

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.