0

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>
2
Contributors
8
Replies
11
Views
7 Years
Discussion Span
Last Post by rouse
0
$("input:radio[name='donation']").click(function() {
    $("#amount").val($(this).val()).attr("disabled", "disabled")
      if($(this).val() == "") {
      $("#amount").attr("disabled", "")
      }
});
0

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.

0

Add the focus() method like so:

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

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

Edited by rouse: n/a

0

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

Edited by Maujor: n/a

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

Edited by Maujor: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.