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
Simple error driving me mad
Old 07-18-2007, 10:55 AM Simple error driving me mad
Guerrilla's Avatar
Ultra Talker

Posts: 424
Trades: -1
Hi guys,

For a scipt im writing I need to refer to a form field using the elements array.

I created a basic script just to send me back the contents of the textfield in an alert box but it doesnt work and I cant figure out what im doing wrong.

Please help.. my code is below

<!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(form){

alert(form.elements[0].value);

return false;
}

</script>

<form onsubmit="return validateThis(this.form);" >
<p>Name:
<input type="text" name="textfield" />
</p>
<p>Phone:
<input type="text" name="textfield2" />
</p>
<p>Email:
<input type="text" name="textfield3" />
</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.
Guerrilla is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-18-2007, 11:37 AM Re: Simple error driving me mad
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Try this:
<form onsubmit="return validateThis(this);">

Or the sure, safe bet:
<form name="myForm" onsubmit="return validateThis(document.myForm);">

The second one will work for sure. I've never tried the first.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 07-18-2007, 12:37 PM Re: Simple error driving me mad
Guerrilla's Avatar
Ultra Talker

Posts: 424
Trades: -1
thanks adam.. all is working now
__________________
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
Guerrilla is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Simple error driving me mad
 

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.89782 seconds with 12 queries