Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
why doesnt this alert() show?
Old 07-20-2007, 10:44 AM why doesnt this alert() show?
Guerrilla's Avatar
Ultra Talker

Posts: 424
Trades: -1
Hey guys,

In the middle of writing a form validation script but the final alert message i want to use isnt showing. if you lok at the code you will see the one i mean. What have i done wrong?

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">

function validateThis(obj){
	// form fields to check
	var fieldRequired = Array("name", "email", "phone");
	// text for alert box if field is empty
	var fieldDescription = Array("Your Name", "Your Email", "Your Phone Number");
	// add the default text of your form
	var defaultText = "empty";
	// The beginning of the alert dialogue if fields are empty, keep \n at the end to preserve formatting
	var alertMsg = "Please complete the following fields\n";
	// loop through each field in fieldRequired and make an alert box to show the information	
    for (var i = 0; i < obj.length; i++){
	// alert("The " + fieldRequired[i] + "is " + obj.elements[fieldRequired[i]].value); // debugging to run through each required value
		if (obj.elements[fieldRequired[i]].value == "" || obj.elements[fieldRequired[i]].value == defaultText){
			alert(fieldRequired[i] + " isn't set");  //debugging to check fields not set
			//alertMsg += "test";
			}
		else {
			alert(fieldRequired[i] + " has been set");
		}	
	} 
	alert("this alert doesnt get displayed");
}

</script>

<form name="myForm"  onsubmit="return validateThis(document.myForm);" >
  <p>Name: 
    <input name="name" type="text" id="name" />
</p>
  <p>Phone: 
    <input name="phone" type="text" id="phone" />
  </p>
  <p>Email:
    <input name="email" type="text" id="email" />
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit"  />
</p>
</form>


</body>
</html>
__________________
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.

Last edited by Guerrilla; 07-20-2007 at 05:13 PM..
Guerrilla is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-21-2007, 02:17 PM Re: why doesnt this alert() show?
Guerrilla's Avatar
Ultra Talker

Posts: 424
Trades: -1
i found out becase the script was erroring out when it come to the submit value in the form array. It says that it is not set. Not sure how I am going to get round it just yet :S
__________________
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
Guerrilla is offline
Reply With Quote
View Public Profile
 
Old 07-22-2007, 10:37 AM Re: why doesnt this alert() show?
Guerrilla's Avatar
Ultra Talker

Posts: 424
Trades: -1
fixed it with some help from another forum, script is finished now
__________________
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
Guerrilla is offline
Reply With Quote
View Public Profile
 
Old 07-22-2007, 12:08 PM Re: why doesnt this alert() show?
xprmnt's Avatar
Extreme Talker

Posts: 212
Name: GiorgosK
Location: Geoland.org - Greece
Trades: 0
Just a sidenote,
alert(argument) with an empty argument won't appear for some browsers,
I forget which ones ....
__________________
GiorgosK
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
xprmnt is offline
Reply With Quote
View Public Profile Visit xprmnt's homepage!
 
Old 07-22-2007, 04:05 PM Re: why doesnt this alert() show?
Guerrilla's Avatar
Ultra Talker

Posts: 424
Trades: -1
thanks xpr, i'll keep an eye out for that. The problem was that the for loop was erroring out. I was passing the whole form object to the loop and when it got to the "submit" field it had no data so the script errored and exited before it got to the alert box. This was fixed by checking if each element had been set first.
__________________
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
Guerrilla is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to why doesnt this alert() show?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22057 seconds with 12 queries