In the following code I just want to disable the textbox if “other Amount is selected”, radio element 7.
I have been working at this too long cause I can’t see the problem. Can someone point out what I am doing incorrectly

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title> Donation page Goes Here </title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <script type="text/javascript" src="../js/jquery.js"></script>
    <body>
        <p>
            Contributions are tax deductable for residents of the United States and Jamaica.
        </p>
        <p>
            Yes, I want to become a contributor. Please accept my donation as indicated below.
            (Contributions in $US only; please check one):
        </p>
        <div id="donationForm">
            <form id="formDonate" name="formDonate" method ='request' onsubmit='return isNumeric();' action='content/creditCardAuthorize.php'>
                <fieldset id="fieldDonate">
                    <legend>Donation Form</legend> <br />
                    <p><input type='radio' id="donation" name='donation' value='10'   /> &nbsp; $10</p>
                    <p><input type='radio' id="donation" name='donation' value='20'   /> &nbsp; $20 </p>
                    <p><input type='radio' id="donation" name='donation' value='30'   /> &nbsp; $30 </p>
                    <p><input type='radio' id="donation" name='donation' value='40'   /> &nbsp; $40 </p>
                    <p><input type='radio' id="donation" name='donation' value='50'   /> &nbsp; $50 </p>
                    <p><input type='radio' id="donation" name='donation' value='75'   /> &nbsp; $75 </p>
                    <p><input type='radio' id="donation" name='donation' value='100'  /> &nbsp; $100</p>
                    <p><input type='radio' id="donation" name='donation' value=''     /> &nbsp; Other Amount </p>
                    <br />
                    <p>
                        <label for='amount'>Amount $</label> <input type='text' name='amount' id='amount' />
                        <span id="errmsg"></span>
                    </p>
                    <p class='submit'><input type='submit' id="donateButton" value='Continue' /></p>
                    <br />
                </fieldset>
            </form>
        </div>
        <script type="text/javascript">
            $("input:radio[@name='donation']").change(function(){
                /*                $("#amount, :text").val( $("input[@name='donation']")); */
                $("#amount, :text").val( $('input[name=donation]:checked').val());
                if(document.formDonate.donation[7].selected){
                    document.formDonate.amount.disabled = false;
                    document.formDonate.amount.focus();
                }
                else{
                    document.formDonate.amount.disabled = true;
                }
            });
            $("#amount").keypress(function (e){
                //if the letter is not digit then display error and don't type anything
                if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)){
                    //display error message
                    $("#errmsg").html("Digits Only").show().fadeOut("slow");
                    return false;
                }
            });
        </script>
    </body>
</html>
Member Avatar for maur
$("input:radio[name='donation']").click(function() {
    $("#amount").val($(this).val()).attr("disabled", "disabled")
      if($(this).val() == "") {
      $("#amount").attr("disabled", "")
      }
});

Maujor:
Thanks!
That worked. I don't understand it yet. I'll have to read it a few more times.
How would I set focus to the #amount text box when it is enabled.

Member Avatar for maur

Add the focus() method like so:

$("#amount").attr("disabled", "").focus();

Thanks, but I don't know where in your code to place it.

Member Avatar for maur

Add the focus() in line #4 of my previous code.

In line for or after line 4?

Member Avatar for maur
$("input:radio[name='donation']").click(function() {
    $("#amount").val($(this).val()).attr("disabled", "disabled")
      if($(this).val() == "") {
      $("#amount").attr("disabled", "").focus();
      }
});

Thanks Maujor!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.