Jump to content

help with field enable/disable...


rsammy

Recommended Posts

i have a screen where apart from other fields, i have these two fields:

<tr>
<td><div align="right"><font class="inputLbl">Wireless
    Access:  </font></div></td>
<td><select name="wirelessaccess" >
<?
	if (isset ($wireless))
	{
	     print ("<option value='$wireless' selected>$wireless</option>");

	     if ($wireless == "Yes")
	     {
		  print("<option value='No'>No</option> ");
	     }
	     elseif ($wireless == "No")
	     {
	          print("<option value='Yes'>Yes</option>");
	     }
	}
	else
	{
	     print("<option value='No' selected>No</option> ");
	     print("<option value='Yes'>Yes</option>");

	}

	?>
  </select></td>
</tr>
<tr>
<td><div align="right"><font class="inputLbl">PIN:  </font></div></td>
<td><input name="phypin" type="text"  class="txtboxLarge" id="phypin" value="<?PHP print($rowz["phy_pin"]); ?>"></td>
</tr>                   

 

what i need to do is, be able to enter some info in the field if the wirelessaccess field takes the value 'Yes'. the field can be made readonly if wireless access field takes 'No'.

 

How can i do this? i am stuck at this point. is this possible with php - i guess php is a server side script. any help will be gladly appreciated. thanx in advance

Link to comment
https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/
Share on other sites

i dont really understand what you are trying to do,

 

you have a select tag, and depending on the results

of what the user selects you want to echo either an

input where the user puts more info or a read only

input tag with pre-written info? is that what you are

trying to do?

no no no. the wirelessaccess field is a drop down with 'Yes' or 'No' as the options. If user selects 'Yes' here, then the next field on screen, PIN is a write only field where user enters a pin ( i am doing PIN validations on this field to make sure the correct one gets thru).

 

If the user chooses 'No' for wirelessaccess field, then the PIN field is made 'readonly' user cannot edit this field. this field may or maynot be blank onload. if wireless acess is 'Yes', the PIN field is mandatory(where user enters info) else the field is readonly(user cannot enter any info).

 

hope im clear now...

oh, now i understand, you can do this with javascript,

try this code before your form

 

<script type="text/javascript">
function checkPin(yesno){
if(yesno == 'yes'){
document.forms[0].phypin.disabled=false;
} else{
document.forms[0].phypin.disabled=true;
}
}
</script>

 

(the code above will only work if this is the only form on that page,

if not add the name attribute to the form and change the 0 in the

brackets where it says forms and add the name of the form)

 

then add this code:

 

<tr>
<td><div align="right"><font class="inputLbl">Wireless
    Access:  </font></div></td>
<td><select name="wirelessaccess" >
<?
	if (isset ($wireless))
	{
	     print ("<option value='$wireless' selected>$wireless</option>");

	     if ($wireless == "Yes")
	     {
		  print("<option onClick=\"checkPin('no')\" value='No'>No</option> ");
	     }
	     elseif ($wireless == "No")
	     {
	          print("<option onClick=\"checkPin('yes')\" value='Yes'>Yes</option>");
	     }
	}
	else
	{
	     print("<option onClick=\"checkPin('no')\" value='No' selected>No</option> ");
	     print("<option onClick=\"checkPin('yes')\" value='Yes'>Yes</option>");

	}

	?>
  </select></td>
</tr>
<tr>
<td><div align="right"><font class="inputLbl">PIN:  </font></div></td>
<td><input name="phypin" type="text"  class="txtboxLarge" id="phypin" value="<?PHP print($rowz["phy_pin"]); ?>"></td>
</tr> 

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.