Javascript based Validation
This will be very easy for someone I'm sure...
How would I tell the form not to submit if a certain fields is equal to 1? I need to do this with Javascript which I'm sure is very simple.
<?php
<head>
<script language=\"javascript\">
function isValidResolution() {
if document.theForm.Resolution == 1;
{
alert('You must select a valid resolution');
return false;
}
}
</script>
</head>
?>
Am I on the right track with that idea?
Jack Michaelson posted this at 18:19 — 24th October 2001.
He has: 1,733 posts
Joined: Dec 1999
<script language="javascript">
function isValidResolution()
{
if (document.theForm.Resolution == "1");
{
alert('You must select a valid resolution');
}
}
</script>
I think...
Shakespeare: onclick || !(onclick)
Vincent Puglia posted this at 15:01 — 25th October 2001.
They have: 634 posts
Joined: Dec 1999
Hi artsapimp,
As Jack implies, you need to surround your condition with parentheses. Also, if Resolution is a text field, you are better off putting the value you are comparing in quotes.
In addition, your form tag must be either using the onSubmit property:
In either case, you need to return false as you had originally.
Vinny
Where the world once stood
the blades of grass cut me still
artsapimp posted this at 17:14 — 25th October 2001.
They have: 330 posts
Joined: Apr 2000
I would not have known that. Thank you.
Art
artsapimp posted this at 17:21 — 25th October 2001.
They have: 330 posts
Joined: Apr 2000
I know I did something wrong, but I can't find it.
Here's the top of my code...
<?php
<!-- #Include File = \"cnn.inc\" -->
<%
'Define SQL statements
strResultSQL = \"SELECT * FROM Result ORDER by Result\"
strDowngradedSQL = \"SELECT * FROM Downgraded ORDER by Downgraded\"
strPerceptionSQL = \"SELECT * FROM Perception\"
strChurnedSQL = \"SELECT * FROM Churned ORDER by Churned\"
?>
<script language=\"javascript\">
function isValidResolution()
{
If (document.theForm.Result.value == \"8\");
{
alert('You must select a result');
return false;
}
}
</script>
Outbound Tracking
Number:
Mailbox Setup?
Yes
No
Result of Call:
<?php
rst.Open strResultSQL, cnn
Do Until rst.EOF
?>
<?php
= rst(\"Result\")
?>
<?php
rst.MoveNext
Loop
rst.Close
?>
?>
Thanks for any help.
Free Math Test
Fun Math Games
Vincent Puglia posted this at 18:34 — 25th October 2001.
They have: 634 posts
Joined: Dec 1999
Hi artsapimp,
My mistake , not yours
tag should read:
Vinny
artsapimp posted this at 20:31 — 25th October 2001.
They have: 330 posts
Joined: Apr 2000
I'm getting an error "object expected" and then it submits the forms. I tried a few things but it's still not working. What is wrong with this?
<?php
<script language=\"javascript\">
function isValidResolution()
{
If (document.theForm.Result.value == \"8\");
{
alert('You must select a result');
return false;
}
}
</script>
<link rel=\"stylesheet\" type=\"text/css\" href=\"/webday/style.css\">
<script language=\"javascript\" src=\"../../validate.js\">
</script>
</head>
<body bgcolor=\"#000000\">
<center>
<form action=\"Submit1.asp\" method=\"Post\" name=\"theForm\" onSubmit=\"return isValidResolution()\">
?>
Thanks again for any help.
Free Math Test
Fun Math Games
Vincent Puglia posted this at 14:48 — 26th October 2001.
They have: 634 posts
Joined: Dec 1999
Hi artsapimp,
1)
If (document.theForm.Result.value == "8");
should be:
if .....
(javascript is case-sensitive)
"Result" is a selection list? If so,
if (document.theForm.Result.options[document.theForm.Result.selectedIndex].value == '8');
Vinny
Where the world once stood
the blades of grass cut me still
artsapimp posted this at 19:34 — 26th October 2001.
They have: 330 posts
Joined: Apr 2000
It is a select box but I still got an error. I changed it to just lower case i and it worked as the first example.
Thanks for your help.
Vincent Puglia posted this at 21:33 — 26th October 2001.
They have: 634 posts
Joined: Dec 1999
Hi artsapimp,
You're welcome, though I'm not sure what you mean and glad it's up and running
Vinny
artsapimp posted this at 21:46 — 26th October 2001.
They have: 330 posts
Joined: Apr 2000
I kept it in this format...
if (document.theForm.Result.value == "8");
with the lowercase i and in "if" and it worked.
I thought you were saying in a drop-down box I would need to change the format to the 2nd example above but that didn't work for me.
Free Math Test
Fun Math Games
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.