I keep getting this error message: expected ')'. Any ideas? function myFunction() { for (i=0; i < document.OrderForm.checkboxes.length; i++){ if(document.OrderForm.checkboxes.checked==true) alert("bla bla bla") } var result = shoppingCart.description + "...$" + shoppingCart.price; JavaScript:top.MAIN.document.clientInfo.message.value = result; } Thanks,
There are a couple of brackets missing. function myFunction() { for (i=0; i < document.OrderForm.checkboxes.length; i++) { if(document.OrderForm.checkboxes[i].checked==true) { alert("bla bla bla") } var result = shoppingCart[i].description + "...$" + shoppingCart[i].price; javascript:top.MAIN.document.clientInfo.message.value = result; } } Code (javascript):
I keep getting the same error message: expected ')' after making the changes you mentioned. My script editor keeps referring to line 31 which is the line where the for loop starts.
One thing I tried was just using the if statement with document.OrderForm.checkboxes.checked and not use the for loop and the error was that document.OrderForm.checkboxes.checked was null or not an object in myChecks(). <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Fall 06</title> <link rel="stylesheet" type="text/css" href="fall06.css" /> </head> <body> <script language="javascript"> <!-- Hide from old browsers var numItems = 0 var shoppingCart = new Object function myChecks(){ for (i=0; i<document.OrderForm.checkboxes.length; i++; ){ if(document.OrderForm.checkboxes.checked=true){ alert("box "+i+" is checked") } } } function myFunction(){ var result = shoppingCart.description + "...$" + shoppingCart.price; JavaScript:top.MAIN.document.clientInfo.message.value = result; myChecks(); } function setFocus(){ document.clientInfo.txtFirst.focus() document.clientInfo.txtFirst.select } function addItem(description, price, itemNum) { this.description = description this.price = price this.itemNum = itemNum this.display = printItem return this } function addtoCart(description, price) { shoppingCart[numItems] = new addItem(description, price, numItems) numItems = numItems + 1 alert(description + "has been added to the bag.") } function deleteItem(itemNum) { delete shoppingCart[itemNum] viewCart() } function printItem(deleteFlag, targetDocument) { with (targetDocument) { write("<TR><TD>" + this.description + "</TD>") write("<TD align=right>$" + this.price + "</td>") if (deleteFlag = true) write("<td><a href='javascript:top.HIDDEN.deleteItem(" + this.itemNum + ")'>Remove from Bag</a></td>") write("</tr>") } } function viewCart() { var cartTotal = 0 with (top.MAIN.document) { write() close() write("<html><title> E-Store</title>") //write('<body onLoad="setFocus()">') write("<center><table border=0><tr>") write("<td align=center valign=bottom>") write("<h1> E-Store Shopping Bag</h1>") write("</td>") write("</tr></center>") write("</table>") write('<center><img src="leaf.jpg"></center>') write("<table border=0 cellpadding=9 cellspacing=1 width=500 bgcolor=ccffff>") for (i in shoppingCart) { cartTotal = cartTotal + shoppingCart.price if (shoppingCart.itemNum != null) shoppingCart.display(true, top.MAIN.document) } write("<document.clientInfo.mytext.value == cartTotal>") write("<tr><td>total:</td><td align=right>$" + cartTotal + "</td>") write("<td> </td></tr></table><br>") //write("<br></center></body></html>") write('<A HREF="eStore.html"><h2><center>Continue shopping...</center></h2></a>') write("<table border=0 cellpadding=9 cellspacing=1 width=700 bgcolor=lightyellow>") write("<tr>") write("<td align=left valign=bottom>") write('<form name="clientInfo" method="post" action="mailto:test@earthlink.net" enctype="text/plain">') write("Enter First Name:<br>") write('<input type="text" name="txtFirst"><br>') write("Enter Last Name:<br>") write('<input type="text" name="txtLast"><br>') write("Select Name:<br>") write('<SELECT NAME="Name" SIZE=0 onblur=>') write('<OPTION VALUE="0">--</option>') write('<OPTION VALUE="1">Ms. A</option>') write('<OPTION VALUE="2">Ms. Al</option>') write('</SELECT><br>') write("Enter E-Mail Address:<br>") write('<input type="text" name="txtemail"><br>') write("Enter Phone Number:<br>") write('<input type="text" name="txtphone"><br><br>') write("Comments:<br>") write('<textarea name="message" cols="40" rows="5"></textarea><br>') write('<center><INPUT TYPE="button" onClick="JavaScript:top.HIDDEN.myFunction();" name="joe" value="Place Order"></center>') //write('<center><INPUT TYPE="button" onClick="myFunction();" name="joe" value="Place Order"></center>') write('<a href="JavaScript:top.HIDDEN.javascript:emailink()";">View Shopping Bag</a>') //write('<a href="#" onClick="clientInfo.message.value = clientInfo.txtFirst.value">View Shopping Bag</a>') write('</form>') write('<td>') write("All prices are subject to change without notice!<br>") write("Call the front office to confirm order and pricing: 238.<br>") write("No deliveries...Items must be picked up at front office during the day before 2:45 p.m.<br>") write('<center><img src="formLogo.gif"></center>') write("</td>") write("</tr>") write('</table>') } } //--> </script> </body> </html>
Semicolons do not come after the iterator of a for statement. function myChecks(){ for (i=0; i<document.OrderForm.checkboxes.length; i++ ){ if(document.OrderForm.checkboxes.checked=true){ alert("box "+i+" is checked") } } Code (markup):
Thank you for seeing that. The for loop works. I didn't have the ; at the beginning, and the loop did not work. Probably because I had the braces wrong as Nico Swd mentioned earlier. Now the error is that document.OrderForm.checkboxes.checked is null or not an object. The checkbox is on another html page within the form code. So maybe I'm not referencing it correctly.
Should be if(document.OrderForm.checkboxes[i].checked=true Code (markup): That assumes that your form contains a group of checkboxes named 'checkboxes'. If so, they may not all get submitted with the form.
The error message is gone, but you are right it doesn't seem to work right. So I'm trying this function myChecks(){ var checkboxes = new Array(1) checkboxes[0] = " Friday T-Shirt " + document.OrderForm.fit.value; JavaScript:top.MAIN.document.clientInfo.message.value = checkboxes; } For each checkbox created I will increase the new Array(1). Now I keep getting the same error message of null or no object with this line: document.OrderForm.fit.value.
[B]checkboxes[/B][0] = " Friday T-Shirt " + document.OrderForm.fit.value; javascript:top.MAIN.document.clientInfo.message.value = [B]checkboxes[/B] Code (markup): Checkboxes is an array. Try checkboxes[0] at the end.
Thanks, I placed checkboxes[0] at the end and still get the null or no object error message referring to this part: document.OrderForm.fit.value. I'm trying to reference the fit.value on another html page and I just can't get it.