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 7 of 7
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    tweak to this code?

    hi,

    this is working great... but i now need to include the enabling/disabling of an extra field.

    here's a working version-> http://www.textit.com.au/x-testradio2.cfm

    I would like to include the sendDate textfield in the 'Schedule for' radio enabling/disabling.

    is this possible?

    PHP Code:
    <html>

    <
    head>
    <
    title></title>
      
    <
    script language="JavaScript" src="console/ts_picker.js">

    //Script by Denis Gritcyuk: tspicker@yahoo.com
    //Submitted to JavaScript Kit (http://javascriptkit.com)
    //Visit http://javascriptkit.com for this script

    </script>

    <script language="JavaScript" type="text/javascript">
    <!--
    // better code by Cory Arthus - 11/23/2005 - http://www.coryarthus.com/
    function enableByName(strName, f) {
        var e = f.elements;
        for ( var i = 0; i < e.length; i++ ) {
            if ( e[i].type != 'radio' && e[i].name != strName&&e[i].type != 'submit' )
                e[i].disabled = true;
            else
                e[i].disabled = false;
        }
    }


    //-->
    </script>

    </head>

    <body onload="enableByName('messageForm',document.forms[0]);">
    <form action="x-testRadio2.cfm" method="post" name="messageForm">
    <input id="R1" type="radio" name="sendNow" value="Y" checked='checked' onclick="enableByName('name1',this.form);" />
      Now<br />
      <br />
      <input id="R3" type="radio" name="sendNow" value="N" onclick="enableByName('sendTime',this.form);" >
      Schedule for 
                        <select name="sendTime">
                        <option value="12:00AM">12:00AM</option>
                        <option value="1:00AM">1:00AM</option>
                        <option value="2:00AM">2:00AM</option>
                        <option value="3:00AM">3:00AM</option>
                        <option value="4:00AM">4:00AM</option>
                        <option value="5:00AM">5:00AM</option>
                        <option value="6:00AM">6:00AM</option> 
                        <option value="7:00AM">7:00AM</option>
                          <option value="8:00AM">8:00AM</option>
                          <option value="9:00AM">9:00AM</option>
                          <option value="10:00AM">10:00AM</option>
                          <option value="11:00AM">11:00AM</option>
                          <option value="12:00PM">12:00PM</option>
                          <option value="1:00PM">1:00PM</option>
                          <option value="2:00PM">2:00PM</option>
                          <option value="3:00PM">3:00PM</option>
                          <option value="4:00PM">4:00PM</option>
                          <option value="5:00PM" selected>5:00PM</option>
                          <option value="6:00PM">6:00PM</option>
                          <option value="7:00PM">7:00PM</option>
                          <option value="8:00PM">8:00PM</option>
                          <option value="9:00PM">9:00PM</option>
                          <option value="10:00PM">10:00PM</option>
                          <option value="11:00PM">11:00PM</option>
                        </select>
                        <input type="Text" name="sendDate" size="6" readonly="yes">
                        <a href="javascript:show_calendar('document.messageForm.sendDate', document.messageForm.sendDate.value);"><img src="console/images/cal.gif" border="0" alt="Click here to pick a date."></a> 
    <br><br>
      
      <input type="submit" name="Submit" value="Submit">
      <br>
    </form>
    </body>

    </html> 
    thanks,

    jo

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    var arrFields = new Array();
    arrFields[0] = []; //fields for radio button 1
    arrFields[1] = ["sendTime", "sendDate"]; //fields for radio button 2
    
    function enableByName(index, f){
      for (var i=0; arrFields.length; i++){
        for (var j=0; arrFields[i].length; j++){
           f.elements[arrField[i][j]].disabled = (index==i) ? false : true;
        }
      }
    }
    ...
    <input id="R1" type="radio" name="sendNow" value="Y" checked="checked" onclick="enableByName(0, this.form);" />
    <label for="R1">Now</label>
    <br />
    <input id="R3" type="radio" name="sendNow" value="N" onclick="enableByName(1, this.form);" >
    <label for="R3">Schedule for</label>
    ...
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi glenngv,

    thank you for the tweak :-)

    I have put that code up here -> http://www.textit.com.au/x-testradio4.cfm

    unfortunately, nothing seems to enable / disable at all??

    thanks,

    jo

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I had a typo.
    Code:
    function enableByName(index, f){
      for (var i=0; arrFields.length; i++){
        for (var j=0; arrFields[i].length; j++){
           f.elements[arrFields[i][j]].disabled = (index==i) ? false : true;
        }
      }
    }
    If you see the Javascript Console, you can easily spot the error.
    BTW, your onload should look like this:
    Code:
    onload="enableByName(0, document.forms[0]);"
    The first parameter is the index position (zero-based) of the selected radio button.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I'm actually getting a 'Page done but with errors' for this code below. Any thoughts as to why this is happening?

    PHP Code:
    <head>
    <
    script language="JavaScript" type="text/javascript">
    <!--
    var 
    arrFields = new Array();
    arrFields[0] = []; //fields for radio button 1
    arrFields[1] = ["sendTime""sendDate"]; //fields for radio button 2

    function enableByName(indexf){
      for (var 
    i=0arrFields.lengthi++){
        for (var 
    j=0arrFields[i].lengthj++){
           
    f.elements[arrField[i][j]].disabled = (index==i) ? true false;
        }
      }
    }
    //-->
    </script>
    </head>


    <body onload="enableByName('messageForm',document.forms[0]);">
    <form action="x-testRadio2.cfm" method="post" name="messageForm"> 
     <input id="R1" type="radio" name="sendNow" value="Y" checked="checked" onclick="enableByName(0, this.form);" /> 
     <label for="R1">Now</label> <br /> 
     <input id="R3" type="radio" name="sendNow" value="N" onclick="enableByName(1, this.form);" > 
     <label for="R3">Schedule for</label>
     <input type="text" name="sendTime"> / <input type="text" name="sendDate">
     <br>
     <input type="submit" name="Submit" value="Submit">
     <br>
    </form>
    </body> 
    thanks :-)

    jo

  • #6
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol. We posted simulataneously :-) thanks for your response. I'll give it a go now... jo

  • #7
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks... that works a treat! wonderful stuff :-)


  •  

    Posting Permissions

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