DevelopPHP.com 2011 Forum Discussion(not active)


check box to show text field
Apr 12, 2011 EJacobowitz wrote:
i need to make a checkbox, that if it is checked it reveals a text field that the end user can put in an old invoice number, and that the data gets sent to the php e-mail form that i already have set up.
Thanks
-Eric
Re:check box to show text field
Apr 12, 2011 wormracer08 responded with:
if ($('#checkboxID').is(':checked')) {
    //show your text field here
}

I would set up your form with all the fields you want and then hide the ones that need some condition to be met before they are shown with css.  For example

input[name=hiddenTextboxName] { display: none; }
then you can use the above code to show the textbox.
Re:check box to show text field
Apr 12, 2011 EJacobowitz responded with:
Okay thanks a lot man!
Re:check box to show text field
Apr 12, 2011 wormracer08 responded with:
Post back if you get stuck

Re:check box to show text field
Apr 12, 2011 Adam responded with:
This is no way to defy or argue with the information already supplied. I wrote it... it works... so I thought I would paste it in.

Paste this code into blank file to see how it runs

<!-- Written by Adam Khoury @ www.developphp.com -->
<html>
<head>
<script type="text/javascript" language="javascript">
function toggleField(field) {
var myTarget = document.getElementById(field);
if(myTarget.style.display == 'none'){
  myTarget.style.display = 'block';
    } else {
  myTarget.style.display = 'none';
  myTarget.value = '';
}
}
</script>
</head>
<body>
<input type="checkbox" onclick="javascript:toggleField('myTF');"/>
Give optional information
<input name="myTF" id="myTF" type="text" style="display:none;" />
</body>
</html>
Re:check box to show text field
Apr 12, 2011 EJacobowitz responded with:
Thanks a lot worm but i used Adams code and it works perfectly! Thanks both of you for taking the time to help me out :)

©2011 DevelopPHP.com