Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation 1

Status
Not open for further replies.

TheCandyman

Technical User
Sep 9, 2002
761
US
I have a simple for in which i'm trying to force the fields to be entered and not left blank. I have some js code which shows the warning "Please fill in..." but still submits anyways. I double checked, and the names for the input boxs are correct to the javascript. I need another pair of eyes on this, because i can't seem to find the problem. Anyone see it?

Code:
<script language="JavaScript" type="text/javascript">
function validateForm() {
with (document.form1) {
var alertMsg = "Please fill in the following attendee information:\n";
	if (FirstName.value == "") {alertMsg += "\n- First Name"}
	if (LastName.value == "") {alertMsg += "\n- Last Name"}
	if (title.value == "") {alertMsg += "\n- Badge Name"}
if (alertMsg != "Please fill in the following attendee information:\n") {
	alert(alertMsg);
	return false;
} else {
return true;
} } }
</script>


Form
Code:
<form ACTION="page.asp" method="post" name="form1" onsubmit="return validateForm()">
 
Are you submitting your form via a submit button (like <input type="submit" value="submit the form">) or by a javascript function (like formName.submit())? When submitting via the javascript method the onsubmit handler will not be called on the form.

If this is not the case then perhaps your conditional statements are not evaluating correctly. I would suggest littering your validation function with alert boxes to see what lines of code are being hit. Specifically the return true line - because if the function is returning false and you are submitting via submit button then there shouldn't be a problem.

On a side note, any particular reason why you've posted 178 questions here at TT and only awarded 4 stars for helpful posts? Surely in your time at TT you've received more than 4 helpful posts....

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Your right Kaht,


This.form.submit();

is what i had done, so i changed it to:

<input type="submit"...


Your other question: i normally thank them, but i only gave stars when they worked with me on a problem for a while. Most posts are a single suggestion, most of the time asking something i had already stated but they didn't RTFS. Which caused the question to be marked with a reply and others pass by it thinking it had been answered. I have written a few times to TT asking for an option for a "question complete", so everyone would know when a question has been answered. anyways....

Unless you think i should be more liberal with the stars??
 
Unless you think i should be more liberal with the stars??

You really can give stars for whatever reason you'd like - there's no hard and fast rule as to why people give stars. I would say most people (myself included) give stars to people that help answer their questions. It is not always the case, but most of the time stars can be associated with threads that are "complete". I know that personally if I were using the search functionalities on the site to find the answer to a question that I haven't yet posted, I would likely read the posts that have been starred first, as they are most likely to be the ones that answer my question. Taking your thread here for example - if someone were to come along later that had a similar question (and solution), it would "stand out" a bit more being starred as a thread where they could find a solution to their problem. Now, as I stated above this is not always the case, and is not a steadfast rule - but it is how I personally perceive the situation.

Additionally, many people come here to answer questions just to receive stars. For me personally, it makes the whole forum process more fun, and more rewarding for offering an answer that helped someone with a problem. Additionally, it helps give a bit of a competitive edge to the users who answer questions here on a regular basis (specifically in the javascript forum with whom I know many of them on a friendship basis, so it's all in good fun).

So, I would say that for most purposes if you feel that someone in a thread has been helpful (as the link implies) that there is no reason not to award them a star. It is encouraged by most "regulars" of the site, and it is unlikely that you would ever be reprimanded for giving too many. Now... not giving enough on the other hand... well, I guess we've already addressed that.

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Damn kaht, I'm almost tempted in giving you a star for this valuable post. I see this:

Your right Kaht,

you're??

and that implies to me that this post was valuable to the poster.


[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
I see your point.

Thanks for taking the time to write that and not just blazing the poster and disappearing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top