...

View Full Version : textbox should be deactivated when the dropdown selects



Mythri
07-16-2012, 03:38 PM
Hi,

i have a dropdown list where i have 3 options like




<tr>
<td><?php echo $entry_shippingtype; ?></td>
<td><select name="type">
<option value="free">Free Shipping</option>
<option value="flat">Flat Rate Shipping</option>

<option value="weight">Weight Based Shipping</option>


</select></td>
</tr>


<tr>
<td><?php echo $entry_shippingamount; ?></td>
<td><input type="text" name="shippingamount" value="<?php echo $shippingamount; ?>" /></td>
</tr>

When i select free shipping shippingamount textbox should be disabled. I dont know how to do it with javascript. Can someone help me please.

abduraooft
07-16-2012, 04:15 PM
<select name="type" onchange="var elm=document.getElementById('shippingamount');if(this.value=='free') elm.disable=true; else elm.disabled=false; ">
<option value="free">Free Shipping</option>
<option value="flat">Flat Rate Shipping</option>

<option value="weight">Weight Based Shipping</option>


</select>

<input type="text" name="shippingamount" id="shippingamount" value="<?php echo $shippingamount; ?>" />

Mythri
07-16-2012, 05:55 PM
But its not taking. I have used like this. Am i doing wrong anywhere?


<tr>
<td><?php echo $entry_shippingtype; ?></td>
<td>
<select name="type" onchange="var elm=document.getElementById('shippingamount');if(this.value=='free') elm.disable=true; else elm.disabled=false; ">
<option value="free">Free Shipping</option>
<option value="flat">Flat Rate Shipping</option>

<option value="weight">Weight Based Shipping</option>


</select></td>
</tr>


<tr>
<td><?php echo $entry_shippingamount; ?></td>
<td><input type="text" name="shippingamount" id="shippingamount" value="<?php echo $shippingamount; ?>" /></td>
</tr>

Philip M
07-16-2012, 06:39 PM
Typo.

elm.disabled=true;

It is your responsibility to die() if necessary….. - PHP Manual

Old Pedant
07-17-2012, 12:42 AM
More efficient:


<select name="type" onchange="this.form.shippingamount.disabled = (this.value=='free');">
...
<input type="text" name="shippingamount" value="...whatever..." />

No need for the id in the text field. And no need for a useless "if" test.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum