Jump to content

hiding the value of a text field?


spouki

Recommended Posts

I have a checkbox and a text field. My goal is to hide the value of the text field when the checkbox is checked. e.g.

 

<form name="form1" action="somepage.php">

<input type="text" name="text1">

<input type="checkbox"  name="checkbox1" onclick=" document.forms[0].text1.value= ' I want to hide this text ' ;     

some_function_to_hide_text();    ">

</form>

 

So is there some sort of function in Javascript that can do this? Your help would be appreciated..

 

Link to comment
https://forums.phpfreaks.com/topic/161359-hiding-the-value-of-a-text-field/
Share on other sites

Something like;

 

<form name="form1" action="somepage.php">
<input type="text" name="text1" id="textInput" />
<input type="checkbox" name="checkbox1" onclick="hideTextInput(this);" />
</form>

<script type="text/javascript">
function hideTextInput(obj) {
textInput = document.getElementById('textInput');
if(obj.checked) {
	textInput.style.display = 'none';
} else {
	textInput.style.display = 'block';
}
}
</script>

 

Not tested

Or, to make ait look a little nicer, just disable the text box;

 

<form name="form1" action="somepage.php">
   <input type="text" name="text1" id="textInput" />
   <input type="checkbox" name="checkbox1" onclick="hideTextInput(this);" />
</form>

<script type="text/javascript">
function hideTextInput(obj) {
   textInput = document.getElementById('textInput');
   if(obj.checked) {
      textInput.disabled=true;
   } else {
      textInput.disabled=false;
   }
}
</script>

When the checkbox is checked, the input field is disabled and a certain value is loaded into the input field (but it is not visible to others)

 

<input type="text"  name="textbox">

<input type="checkbox" name="checkbox1"  onclick="this.form.textbox.disabled= this.checked;   

this.form.textbox.value='99';  "   >  

 

// making "99" not visible is all what i need

                           

                         

 

 

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.