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
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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

Ok, you're going to have to explain this to me a bit better.

 

- page loads

- input field is there but has no value?

- checkbox is clicked and the value is loaded into the input field?

- check is again and it disapears

 

??

Link to comment
Share on other sites

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

                           

                         

 

 

Link to comment
Share on other sites

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.