PDA

View Full Version : Weird JavaScript/MySQL issue



rocg23
04-24-2007, 04:05 PM
I am running two JavaScripts on one page, to make sure that no more then 2 checkboxes are checked for one option and no more then three for another. Where I am having the problem is, when putting the data into the database, it doesn't see the data from within the second JavaScript.

If I remove the second script it works fine, but then I can't monitor the number of boxes checked.



<script type="text/javascript" language="javascript">
var MeatCount=0
var maxMeat=2

function count(meat)
{
if(meat.checked)
{MeatCount=MeatCount+1}

else
{MeatCount=MeatCount-1}

if (MeatCount>maxMeat)
{Meat.checked=false
MeatCount=MeatCount-1
alert('Sorry, you may only choose '+maxFreeItems+' meats. ')
}
}
</script>

<FORM method="" action="" name="checkmeat">
<tr>
<td colspan="2"><b>Please choose two meats</b></td>
</tr>
<tr>
<td align="right">
Buffalo Chicken <INPUT TYPE="checkbox" NAME="addarray[]" value="Buffalo Chicken" onclick="count(meat)"><br>

Fried Chicken Breast <INPUT TYPE="checkbox" NAME="addarray[]" value="Fried Chicken Breast" onclick="count(meat)"><br>

Grilled Chicken Breast <INPUT TYPE="checkbox" NAME="addarray[]" value="Grilled Chicken Breast" onclick="count(meat)"><br>

Fried Chicken Cutlet <INPUT TYPE="checkbox" NAME="addarray[]" value="Fried Chicken Cutlet" onclick="count(meat)"><br>

Turkey <INPUT TYPE="checkbox" NAME="addarray[]" value="Turkey" onclick="count(meat)"><br>

Smoked Turkey <INPUT TYPE="checkbox" NAME="addarray[]" value="Smoked Turkey" onclick="count(meat)"><br>

Roast Beef <INPUT TYPE="checkbox" NAME="addarray[]" value="Roast Beef" onclick="count(meat)"><br>

Ham <INPUT TYPE="checkbox" NAME="addarray[]" value="Ham" onclick="count(meat)"><br>
</td>
<td align="left">
<INPUT TYPE="checkbox" NAME="addarray[]" value="Bacon" onclick="count(meat)"> Bacon <br>

<INPUT TYPE="checkbox" NAME="addarray[]" value="Prosciutto" onclick="count(meat)"> Prosciutto <br>

<INPUT TYPE="checkbox" NAME="addarray[]" value="Sopressata" onclick="count(meat)"> Sopressata <br>

<INPUT TYPE="checkbox" NAME="addarray[]" value="Salami" onclick="count(meat)"> Salami <br>

<INPUT TYPE="checkbox" NAME="addarray[]" value="Pepperoni" onclick="count(meat)"> Pepperoni <br>

<INPUT TYPE="checkbox" NAME="addarray[]" value="Sweet Sausage" onclick="count(meat)"> Sweet Sausage <br>

<INPUT TYPE="checkbox" NAME="addarray[]" value="Meatballs" onclick="count(meat)"> Meatballs <br>

<INPUT TYPE="checkbox" NAME="addarray[]" value="Fried Eggplant" onclick="count(meat)"> Fried Eggplant
</FORM>
</td>
</tr>





<script type="text/javascript" language="javascript">
var TopCount=0
var maxTops=3

function count(tops)
{
if(tops.checked)
{TopCount=TopCount+1}

else
{TopCount=TopCount-1}

if (TopCount>maxTops)
{tops.checked=false
TopCount=TopCount-1
alert('Sorry, you may only choose '+maxFreeTops+' toppings. ')
}
}
</script>

<FORM method="" action="" name="checktops">
<tr>
<td colspan="2"><b>Please choose three toppings</b></td>
</tr>
<tr>
<td align="right">
Lettuce <INPUT TYPE="checkbox" NAME="addarray2[]" value="Lettuce" onclick="count(tops)"><br>

Romain <INPUT TYPE="checkbox" NAME="addarray2[]" value="Romain" onclick="count(tops)"><br>

Onion <INPUT TYPE="checkbox" NAME="addarray2[]" value="Onion" onclick="count(tops)"><br>

Tomato <INPUT TYPE="checkbox" NAME="addarray2[]" value="Tomato" onclick="count(tops)"><br>

Sun-Dried Tomatoes <INPUT TYPE="checkbox" NAME="addarray2[]" value="Sun-Dried Tomatoes" onclick="count(tops)"><br>

Roasted Red Peppers <INPUT TYPE="checkbox" NAME="addarray2[]" value="Roasted Red Peppers" onclick="count(tops)"><br>

Olives <INPUT TYPE="checkbox" NAME="addarray2[]" value="Olives" onclick="count(tops)"><br>

Sliced Garlic Pickle <INPUT TYPE="checkbox" NAME="addarray2[]" value="Sliced Garlic Pickle" onclick="count(tops)"><br>

Cucumber <INPUT TYPE="checkbox" NAME="addarray2[]" value="Cucumber" onclick="count(tops)"><br>

Carrot <INPUT TYPE="checkbox" NAME="addarray2[]" value="Carrot" onclick="count(tops)"><br>

Cranberry Sauce <INPUT TYPE="checkbox" NAME="addarray2[]" value="Cranberry Sauce" onclick="count(tops)"><br>

Oregano <INPUT TYPE="checkbox" NAME="addarray2[]" value="Oregano" onclick="count(tops)"><br>

Basil <INPUT TYPE="checkbox" NAME="addarray2[]" value="Basil" onclick="count(tops)"><br>
</td>
<td align="left">
<INPUT TYPE="checkbox" NAME="addarray2[]" value="Basil Pesto" onclick="count(tops)"> Basil Pesto <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="BBQ Sauce" onclick="count(tops)"> BBQ Sauce <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Gravy" onclick="count(tops)"> Gravy <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Horseradish Sauce" onclick="count(tops)"> Horseradish Sauce <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Sauce" onclick="count(tops)"> Sauce <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Oil & Vinegar" onclick="count(tops)"> Oil & Vinegar <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Mayo" onclick="count(tops)"> Mayo <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Mustard" onclick="count(tops)"> Mustard <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Chipotle Mustard" onclick="count(tops)"> Chipotle Mustard <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Italian Dressing" onclick="count(tops)"> Italian Dressing <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Blue Cheese Dressing" onclick="count(tops)"> Blue Cheese Dressing <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Caesar Dressing" onclick="count(tops)"> Caesar Dressing <br>

<INPUT TYPE="checkbox" NAME="addarray2[]" value="Ranch Dressing " onclick="count(tops)"> Ranch Dressing
</FORM>
</td>
</tr>


These are both separate files "included" in a PHP script.