Jump to content

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

                           

                         

 

 

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.