Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post

    defult value appears when a textbox is enabled

    hey people,

    i have four radio button options, with 4 textboxes linked to each of the radio button, the textboxes are disabled until a radio button is selected. when a particular radio button is selected, the textbox to which the selected radio button is linked is enabled, im trying have a default value setup for one of the textboxes, so if the radio button is selected, the textbox should show a a default value as soon as it is enabled

    the coding so far is shown below:

    Code:
    <td>
    	 
    	&bull; Lamb Ribs<input type="hidden" id="lamb7" value="4.99"/>
    	<br/>
    	Price: £4.99 per KG
    	</td>
    	  <td bgcolor="green">
                </td>
              <td align="right" width="200px">
    	<input type="radio" name="lambR" onclick="lRibs(1)"/>in KG:	<input type="text" name="lambRibs1" id="lambRibs1" size="2" value="" disabled="disabled"/>
        <br/>
        <br/>
        <input type="radio" name="lambR" onclick="lRibs(2)"/>in lbs:	<input type="text" name="lambRibs2" id="lambRibs2" size="2" value="" disabled="disabled"/>
         <br/>
        <br/>
        <input type="radio" name="lambR" onclick="lRibs(3)"/>in money:	£<input type="text" name="lambRibs3" id="lambRibs3" size="4" value="00.00" disabled="disabled"/>
         <br/>
        <br/>
        <input type="radio" name="lambR" onclick="lRibs(4)"/>quantity:	<input type="text" name="lambRibs4" id="lambRibs4" size="2" value="" disabled="disabled"/>
    
    	<script type = "text/javascript">
    
    function lRibs (which) {
    var len = document.forms[0].lambR.length;  // how many radio buttons in group?
    for (var i =1; i<=len; i++) {  // for all the textboxes
    document.forms[0]["lambRibs" + i].value = "";  // clear the field
    document.forms[0]["lambRibs" + i].disabled = true; // disable the textbox
    }
    document.forms[0]["lambRibs" + which].disabled = false;  // enable selected textbox
    }
    
    </script>
    	</td>
    the radio button option that i am concerned with regarding the default value is:

    Code:
    <input type="radio" name="lambR" onclick="lRibs(3)"/>in money:	£<input type="text" name="lambRibs3" id="lambRibs3" size="4" value="00.00" disabled="disabled"/>
    i placed the value 00.00 on the textbox, however when i select the radio button, it is blank.

    would reallly appreciate it if someone could help

    thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,542
    Thanks
    77
    Thanked 4,382 Times in 4,347 Posts
    Ummm....

    In *YOUR* code:
    Code:
        document.forms[0]["lambRibs" + i].value = "";  // clear the field
    Why are you surprised that it is blank when you force it to be?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Razzy (07-09-2012)

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    14
    Thanked 1 Time in 1 Post
    lol wow thank for that


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •