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 to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Text Field Depending on Radio Options.

    PHP Code:

    this is php with javascript running
    <br /><br />


    <
    script type="text/javascript">
    function 
    makeChoice()
    {
    var 
    val 0;
    for( 
    0document.form1.accno.lengthi++ )
    {
    if( 
    document.form1.accno[i].checked == true )
    {
    val document.form1.accno[i].value;
    if(
    val=='cedu')
    {
    document.form1.otherChoice.disabled=false;
    document.form1.otherChoice.focus();
    }
    else
    {
    document.form1.otherChoice.disabled=true;
    }
    }
    }
    }
    </script>


    <body onload="document.form1.otherChoice.disabled=true">
    <form name="form1" action="#" method="post">
    <tr>

    <td>
    <input type="radio" name="accno" value="1" onclick="makeChoice();" />
    Yes<input type="radio" name="accno" value="cedu" onclick="makeChoice();"/>
    No</td>
    </tr>
    <tr
    <td><br />Global Account Number:</td>
    <td><input type="text" name="otherChoice" />
    </td>
    </tr>
    </form> 

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And your question is?
    Anyway, here is an optimised version of your code
    PHP Code:
    <script type="text/javascript"
    function 
    makeChoice(select)
    {
        if(
    select)
        { 
            
    document.form1.otherChoice.disabled=true
        }
        else
        { 
            
    document.form1.otherChoice.disabled=false
            
    document.form1.otherChoice.focus(); 
        }

    </script>

    <body onload="makeChoice(0)"> 
    <form name="form1" action="#" method="post"> 
        <tr> 
            <td> 
                <input type="radio" name="accno" value="1" onclick="makeChoice(1)" /> Yes
                <input type="radio" checked="checked" name="accno" value="cedu" onclick="makeChoice(0)"/> No
            </td> 
        </tr>
        <tr>
            <td>
                <br />Global Account Number:
            </td> 
            <td>
                <input type="text" name="otherChoice" /> 
            </td>
        </tr>
    </form> 

  • #3
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,460
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Actually, hyperionXS, this forum is for people to post working snippets of code, not code they need help with specifically.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog


  •  

    Tags for this Thread

    Posting Permissions

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