Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.