Member Avatar for Amoryethel

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>

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>
Member Avatar for Amoryethel

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?

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.

Member Avatar for Amoryethel

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

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.