0

I'm trying to put together a webpage that will leave a dropdown menu (near merch1) disabled until the checkbox is selected, but the dropdown menu insists on staying disabled. I don't know if it has to do with my checkBox function, or if that's even a necessity. Here is a small excerpt of my code.

/* <![CDATA[ */
var cart1 = 0;

function checkBox(name)
{
    document.getElementById(name).enabled = !document.getElementById(name).enabled;
}

function calcTotal
{
    var sheet1 = parseInt(document.buy.merch1.value);

    if (document.buy.MusicSheet1.checked)
    {
        document.buy.merch1.disabled = false;
        cart1 = (sheet1 * 4.95);
    }
    else
    {
        document.buy.merch1.disabled = true;
        cart1 = 0;
    }   
}
/* ]]> */
<form id="buyForm" name="buy">
<tr>
<td>
    <input type="checkbox" name="MusicSheet1" onchange="checkBox('one')" /> We Will All Go Together sheet music, $4.95
</td>
<td>
    <select name="merch1" id="one" onchange="calcTotal()" disabled="disabled">
    <option value="0" selected="selected"></option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option></select>  
</td>
</tr>
</form>
2
Contributors
4
Replies
10
Views
4 Years
Discussion Span
Last Post by Amoryethel
0

Two minor changes to your script...

1) checkBox function
2) you forgot to add "()" after the function name "calcTotal"

Here is the updated script...

<script>
var cart1 = 0;
function checkBox(name)
{
    document.getElementById(name).disabled = !document.getElementById(name).disabled;
}
function calcTotal()
{
    var sheet1 = parseInt(document.buy.merch1.value);
    if (document.buy.MusicSheet1.checked)
    {
        document.buy.merch1.disabled = false;
        cart1 = (sheet1 * 4.95);
    }
    else
    {
        document.buy.merch1.disabled = true;
        cart1 = 0;
    }   
}
</script>

Edited by JorgeM

0

Thank you for the quick response! If my script isn't the cause of the drop down menu being re-enabled, was there something that isn't necessary where MusicSheet1 and merch1 sits?

1

I only made changes to the script specifically the code I pasted above. I didn't touch any other code or HTML markup.

I tested it before I posted it because it was working with the minor changes I made.

Edited by JorgeM

0

My mistake. One of my other functions were missing parentheses as well, causing my code to be unresponsive. :) Thank you for your help!

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.