Hi i wrote a function to validate my input but what is happening is that it kicks me out and alerts me to the first issue, but then once the clubname is done the
other checks do not execute and it writes to the db without validating the remaining inputs.
here is the function
Code:
<script type="text/javascript">
function validate_thisinfo()
{
/* clubname */
if (document.clubform.clubname.value.length < 1)
{
alert("Club Name is a required field.");
document.clubform.clubname.focus();
return(false);
}
if (document.clubform.clubname.value.length > 50)
{
alert("Club Name is limited to 50 char.");
document.clubform.clubname.focus();
return(false);
}
/* clubcity */
if (document.clubform.clubcity.value.length < 1)
{
alert("Club City is a required field.");
document.clubform.clubcity.focus();
return(false);
}
if (document.clubform.clubcity.value.length > 50)
{
alert("Club City is limited to 50 char.");
document.clubform.clubcity.focus();
return(false);
}
return(true);
}//close function validate_thisinfo
</script>
So what happens is that it alerts me when clubname is blank but when i input club name and leave city blank it should alert me again when i
click submit but it does not it just writes to the db without validating the city or any other info.
It should return false unless it passes all tests then returns true.
Im not sure why it is not re exicuting the function every time i click submit.
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
Changed and still doing same thing, catches the first if statment but then once that is fixed it does not execute or revalidate on click and writes to db
and all my other scripts that work use return (value); not return value; so im not sure what i missed here
For form validation, you aren't returning a value. return false; prevents the form from being submit. Or, at least it's supposed to.
Have you checked the error console to see if any JavaScript error messages are being presented? If the JavaScript is breaking, this would allow the form to submit.
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
no errors i did validate with php because i want to do both javascript popups and also errorpage so the php is working but i still cant get the javascript to revalidate, pretty strange.
Im still digging, i copied a function from another script that works and same thing. Really wierd stuff.
I will keep you posted, if you have any ideas please share, maybe you have something i can post in there to test if javascript is working right.
I also just tried this and nothing, no reaction at all when i left the field. And yes did change the function hame to validateinfo i was easier to remember lol
Update: i did a test where i changed the onClick to another function that just checks one if statment at a time, i put one statement in there. And it worked, so the issue must be with having multiple statments...
Update 2 i think i may be onto something here, i just added another if to that function and they both worked, got two popups so now i will try adding one at a time to that function and see what happens. really really strange stuff i swear never a dull moment...
I got it working, i had mispelled one of the vars in the function grrrrrrr im so embarrassed. Also i guess if all passes it defaults to return true because i removed the return true from the function and if all data is correct it it submits.
is that correct, does it default to true unless it is changed to false?
I am out of ideas. The brackets are opened/closed properly. The code looks good. I'm stumped as to why the error console is not showing any error messages. Are you using IE or FF?
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
You should attach an "onsubmit" attribute to the form rather than "onclick" to the submit button.
Code:
<form id="frmContact" action="" method="post" onsubmit="return validateinfo(this);">
function validateinfo(frm) {
// return false to prevent form submission..
// otherwise, do nothing and the form will submit.
}
You can still use "onblur", etc., to validate data as they complete the form but returning true/false from such events will have no affect on the form submission. I would, therefore, not use the same function for these different events.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
thanks everyone im glad i finally got it, i guess i learned what happens when one part of the javascript fails, i would assume it would all fail or that i would get a message so not sure what happened because it ran the first if and then failed and the typo was on the third if statment that i added. Strange how the first one worked and then nothing else. lesson learned on several levels here.