The problem I’m having with this one is in the function, with the FOR I’ve hilited. This is a test pizza ordering application, where I have checkboxes for the different toppings. There are 3 buttons, ( I bet you guys have all seen this at one time or another!), for either Veggie, Meat or Hawaiian, and, depending on which botton is clicked, the appropriate check boxes should be automatically filled in. I have that part working; however, my intention with that FOR is to clear all the checkboxes before the user makes an entry, so that, when they change their mind, the boxes that have previously been checked are first cleared. ( Or, more accurately, ALL the boxes are cleared). Instead, what’s happening is that no matter what choice I make, all the boxes wind up being checked. Can you tell me what’s wrong?
Thanks!,
Jeff S
[FONT=“Courier New”]!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>Pizza</title>
<script type = “text/javascript”>
function flip(pizzatype) { for (var i=0; i<7; i++) {
document.forms[“pizzaform”].toppingcheck[i].checked=“false”; }
if (pizzatype.value==“Veggie Special”) {
document.forms[“pizzaform”].topping.value = “veggies”;
document.forms[“pizzaform”].toppingcheck[3].checked=“checked”;
document.forms[“pizzaform”].toppingcheck[4].checked=“checked”;
document.forms[“pizzaform”].toppingcheck[5].checked=“checked”;
} else if (pizzatype.value==“Meat Special”) {
document.forms[“pizzaform”].topping.value = “meat”;
document.forms[“pizzaform”].toppingcheck[0].checked=“checked”;
document.forms[“pizzaform”].toppingcheck[1].checked=“checked”;
document.forms[“pizzaform”].toppingcheck[2].checked=“checked”;
} else if (pizzatype.value==“Hawaiian”) {
document.forms[“pizzaform”].topping.value = “hampineapple”;
document.forms[“pizzaform”].toppingcheck[6].checked=“checked”;
document.forms[“pizzaform”].toppingcheck[2].checked=“checked”;
}
}
This works. I have modified some of your script to make use of the name attributes of the form element. Have a close look at the differences between your original script and this one to see what I have done.
Thanks guys. I appreciate it. It WORKS! Allan, I didn’t change it to the way you suggested; it essentially appeared to be the same thing I was already doing – with the slight exception that you were doing it CORRECTLY! But, after making that string a boolean, it worked fine just the way I had it.
It’s a small improvement, and the immediate benefit may not be clear until you have made many small improvements, and then come back to it several months later.
PHP will see them, but only the last value will be easily accessible. If the OP wants a useful reference, PHP has some good info on how to create arrays in an HTML <form>
Thanks all,I’m all for improved code! You guys are getting a little ahead of me on the server side stuff…I’ll try and remember about the for PHP, but I haven’t even started looking at any server-side yet – I’ve done a beginners 500 page HTML/CSS book, and now a little over 1/2 way thru beginners javascript. Then I was thinking I might do another html/css and a little more advanced javascript, or maybe if I can just find some practice javascript apps I can try and write, just to get more comfortable with what I should already know before moving on to server side…