So I want to show hide various parts of a form based on html form entries and this is what I have so far.
<script language="JavaScript">
function showhidefield(method)
{
if (method = 1)
{
document.getElementById("hideablearea").style.display = 'block';
document.getElementById("hideablearea2").style.display = 'none';
document.getElementById("hideablearea3").style.display = 'none';
}
if (method = 2)
{
document.getElementById("hideablearea").style.display = "none";
document.getElementById("hideablearea2").style.display = "block";
document.getElementById("hideablearea3").style.display = "block";
}
if (method = 3)
{
document.getElementById("hideablearea").style.display = "block";
document.getElementById("hideablearea2").style.display = "block";
document.getElementById("hideablearea3").style.display = "block";
}
else
{
document.getElementById("hideablearea").style.display = "none";
document.getElementById("hideablearea2").style.display = "none";
document.getElementById("hideablearea3").style.display = "none";
}
}
</script>
</head>
<body>
<form name="newentry" method="post" action="registration.php" onSubmit="return formCheck(this) && validatePwd() && checkEmail() ;">
<table border="0" width="225" align="center">
<tr>
<td width="219" bgcolor="#999999">
<p align="center"><b><span style="font-size: 12pt"><font color="white">New Reminder</font></span></b></p>
</td>
</tr>
<tr>
<td width="219">
<table border="0" width="282" align="center">
<tr>
<td width="116"><span style="font-size:10pt;">Method:</span></td>
<td width="156"><select name="method" onChange= "showhidefield(document.getElementById('method').value)">
<OPTION VALUE="0"></OPTION>
<option value="1">Email</option>
<option value="2">Text Message</option>
<option value="3">Both</option></td>
</tr>
<tr id='hideablearea' style='display:none;'>
<td width="116"><span style="font-size:10pt;">Email:</span></td>
<td width="156">
<input type="text" name="email" maxlength="100"></td>
</tr>
<tr id='hideablearea2' style='display:none'>
<td width="116"><span style="font-size:10pt;">Cell:</span></td>
<td width="156"><input type="text" name="cell" maxlength="10"></td>
</tr>
<tr id='hideablearea3' style='display:none'>
<td width="116"><span style="font-size:10pt;">Carrier:</span></td>
<td width="156"><select name="carrier"><OPTION VALUE="">
<option value="@message.alltel.com">Alltel</option>
<option value="@txt.att.net">ATT</option>
</select></td>
</tr>
Basically a form field called method asks weather the person wants to be contacted by Email, Cellphone or both if they choose Email: only the email field will show, and if they choose cellphone: the cell number and carrier dropdown menu will be shown.
I have tried this in many different ways (placing attributes in form elements etc.) with no success. Any ideas?!
Thanks!