Jump to content

How Do I Check A Value Before Submitting A Form


confused and dazed

Recommended Posts

Hello folks.Here is my problem.I have a bunch of hidden id's with values but I need to check to see if those values are right before I submit my form. I tried an if statement but it is just not working. I am trying something like Function checkquad(){if(r1.value="");if(r2.value="");{alert("r1 and r2 not filled out right");}} What I am trying to say with my if statements is that if the value r1 and r2 (from a from I named tourney) do not have a value set yet then send out the alert and dont submit the form... Not working...

Link to comment
Share on other sites

Putting tags on the page doesn't define arbitrary variables in every Javascript function. You need to actually get references inside Javascript to the HTML elements on the page. HTML and Javascript aren't the same thing. Check the link I posted. Your if statement also isn't structured correctly, check the tutorial about if statements: http://www.w3schools.com/js/js_if_else.asp Note that you don't put a semicolon after the condition. Writing this:if(r1.value=""); Is the same as doing nothing: if(r1.value=""){ } Example 3 on the above link shows an example where they test two conditions with an AND, but you probably want to use OR. This page has examples of using AND and OR operators: http://www.w3schools.com/js/js_comparisons.asp Also on that page, look at the == operator. That's the one you need to use in an if statement. When you use = it assigns a value, when you use == it compares values.

Link to comment
Share on other sites

O.K. i was able to fix my comparison issue with ==, thanks. But I still cannot seem to pull the value of r1 into the value for quad function show_alert(){quad ="document.tourney.r1.value"; //tourney is the name of the form where r1 exsists if(quad=="higher") //higher is the value of the hidden value r1 { alert("Hello! yes"); } else { alert("nope"); }}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...