Forum Moderators: open

Message Too Old, No Replies

Problems with Functions

I need multiple event handlers and it isn't working

         

TheSooner3

7:23 am on Dec 11, 2009 (gmt 0)

10+ Year Member



So I have a food delivery example set up. I have three necessary buttons.
1) Pickup
2) Delivery
3) Submit to Confirmation
I want/have the submit button disabled until they pick one of the first two, so if they click pickup, I have onClick="continue()", in which an If statement checks to see if the customer has filled his name in in a text field, then will make the submit available. They delivery has onClick="delivery()" and checks for name but also makes address text field available, after checking that, then will the submit button become available. My problem is that I can't seem to get both functions to work together, individually they seem fine. I'm sure and I hope this is just a simple mistake that I have not learned yet. Any help would be much appreciated!

<html>
<head>
<title>Ric's Pizza - Order</title>
<link rel=stylesheet href="style.css" type="text/css">

<script language="JavaScript">
function continue() {
with (document.order) {
if (document.getElementById("tf1").value=="") {
alert("Please enter your name to continue.");
else {
document.getElementById("tf4").disabled=false;
}
}}
function delivery() {
with (document.order) {
if (document.getElementById("tf1").value=="") {
alert("Please enter your name to continue.");
}
else if {
document.getElementById("tf2").disabled=false;
document.getElementById("tf3").disabled=false;
}
else if (document.getElementById("tf2").value=="") {
alert("Please enter your address to continue.");
}
else if (document.getElementById("tf3").value=="0") {
alert("Please enter your city to continue.");
}
else {
document.getElementById("tf4").disabled=false;
}
}}
</script>
</head>

astupidname

8:42 am on Dec 11, 2009 (gmt 0)

10+ Year Member



"continue" is a reserved word in javascript (continue is a statement), re-name your "continue" function to something else. Also there appears to be no need (even if appearances deceive, there IS no need) for the "with" statements either.

TheSooner3

9:37 am on Dec 11, 2009 (gmt 0)

10+ Year Member



Alright thanks, I was actually just using "continue" because it made more sense, I was actually using doCont(). But that's good to know for the future haha. Fortunately I figured this problem out, now I am in some more confusing situations. I appreciate the help even though these questions are pretty basic.