Reply LinkBack Thread Tools Search this Thread
Old 13-09-2005, 04:45   #1 (permalink)
finbarr
who the fuck am i?
 
finbarr's Avatar
 
Join Date: Apr 2005
Location: london
Posts: 2,660
Send a message via MSN to finbarr Send a message via Skype™ to finbarr
form checking with javascript

want to apply some javascript checking to a form. I have the script but dont know how to apply it. I'm pretty sure that someone told me it shouldnt be done on submit but cant remember the solution.
Can anyone help? In plain english if possible - I'm not a coder
  Reply With Quote
Old 13-09-2005, 04:52   #2 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
I use this.
HTML Code:
<form name="comment" action="contact.php" method="post" onsubmit="return checkForm()"> <label for="name">Name *</label> <input type="text" name="name"/><br/> <label for="email">e-mail *</label> <input type="text" name="email"/><br/> <label for="comments">Your comments</label> <textarea name="comments"></textarea><br/> <input type="hidden" name="send" value="1" /> <input type="image" src="images/void.gif" class="submit" alt="Send" title="Send the message"/> </form> <script type="text/javascript" language="javascript"> function checkForm() { f = document.comment; if (f.name.value == '') { alert("Please tell me what is your first name"); f.name.focus(); return false; } if (f.email.value == '') { alert("So, what is your email?"); f.email.focus(); return false; } } </script>
It works on submit, though
  Reply With Quote
Old 13-09-2005, 04:57   #3 (permalink)
Narate
Royalty™
 
Narate's Avatar
 
Join Date: Feb 2003
Location: Manchester (UK)
Posts: 3,270
Quote:
"So, what is your email?"

Thats abit pushy
  Reply With Quote
Old 13-09-2005, 04:59   #4 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
It is, isn't it?
  Reply With Quote
Old 13-09-2005, 05:10   #5 (permalink)
finbarr
who the fuck am i?
 
finbarr's Avatar
 
Join Date: Apr 2005
Location: london
Posts: 2,660
Send a message via MSN to finbarr Send a message via Skype™ to finbarr
I have the javascript as a separate file thats supposed to kick in before the user is directed to an asp page which sends an email to the site owner and thanks the user for their enquiry. Does this make a difference?
  Reply With Quote
Old 13-09-2005, 05:12   #6 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
basically no. I just got too lazy to take it out.
It would help if you posted the code...
  Reply With Quote
Old 13-09-2005, 05:22   #7 (permalink)
finbarr
who the fuck am i?
 
finbarr's Avatar
 
Join Date: Apr 2005
Location: london
Posts: 2,660
Send a message via MSN to finbarr Send a message via Skype™ to finbarr
Quote:
Originally Posted by emilpaun
It would help if you posted the code...
Will do Emil, as soon as I think its complete. Basically I'm a coding fuckwit but I still like to take things as far as I can before admitting defeat. If I dont try I wont learn, will I?
But thanks for your help so far... why arent you a DT forum leader?
  Reply With Quote
Old 13-09-2005, 05:24   #8 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
*blushing*
  Reply With Quote
Old 13-09-2005, 05:28   #9 (permalink)
smallbeer
I Ain't Losing Any Sleep™
 
Join Date: Apr 2003
Posts: 5,205
he's a johnny foreigner.

the gates are closed.
  Reply With Quote
Old 13-09-2005, 05:30   #10 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Quote:
Originally Posted by smallbeer
the gates are closed.
Something I am really used to.
  Reply With Quote
Old 13-09-2005, 05:35   #11 (permalink)
d*d
Moderator
 
d*d's Avatar
 
Join Date: Oct 2004
Location: Bristol
Posts: 3,394
Since were talking about javascript and form elements, is there a way to submit a form automatically using javasrcript when a dropdown menu item is selected instead of using the submit button?
  Reply With Quote
Old 13-09-2005, 05:44   #12 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
I think you can use onSelect. But then I think it would be difficult, if someone is trying to use the keyboard to select something...

<select name="whateverName" onselect="javascript:document.formName.submit()">
<option value="0">select</option>
<option value="1">one</option>
</select>
  Reply With Quote
Old 13-09-2005, 06:14   #13 (permalink)
finbarr
who the fuck am i?
 
finbarr's Avatar
 
Join Date: Apr 2005
Location: london
Posts: 2,660
Send a message via MSN to finbarr Send a message via Skype™ to finbarr
Quote:
Originally Posted by d*d
Since were talking about javascript and form elements, is there a way to submit a form automatically using javasrcript when a dropdown menu item is selected instead of using the submit button?
hey, wheres the pig gone?
  Reply With Quote
Old 13-09-2005, 06:17   #14 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
He's probably eaten it.
  Reply With Quote
Old 13-09-2005, 06:45   #15 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: London, UK
Posts: 1,945
dreamweaver has a javascript form checker, you can download a free alternative for dreamweaver which is a lot better from: http://www.yaromat.com/dw/?ex=Check%20Form%20MX

You'll need the macromedia extension manager installed which you can get from: http://www.macromedia.com/exchange/em_download/

It's as simple as adding a behaviour to the form and then clicking a few check boxes and changing a few options and it'll do it all for you and whack in the necessary code
  Reply With Quote
Old 13-09-2005, 06:47   #16 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: London, UK
Posts: 1,945
Quote:
Originally Posted by d*d
Since were talking about javascript and form elements, is there a way to submit a form automatically using javasrcript when a dropdown menu item is selected instead of using the submit button?

once again, dreamweaver has an inbuilt function for this.. when creating a form you can click the jump menu form element, and hey presto, there it is
  Reply With Quote
Old 13-09-2005, 07:05   #17 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,482
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Quote:
Originally Posted by stealthcow
dreamweaver has a javascript form checker, you can download a free alternative for dreamweaver which is a lot better from: http://www.yaromat.com/dw/?ex=Check%20Form%20MX
Nice one that
  Reply With Quote
Old 13-09-2005, 16:10   #18 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,041
Send a message via MSN to paulanthony
Anyone come across a more open ended javascript validation script - that you can use on different forms without having to change the code too much - i.e. a validation class in javascript?
__________________
  Reply With Quote
Old 13-09-2005, 16:53   #19 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: London, UK
Posts: 1,945
that wouldnt make sense paul, because the required fields on each form would change

plus, the dreamweaver option makes it very to apply it to new forms
  Reply With Quote
Old 13-09-2005, 17:52   #20 (permalink)
Transmogrify
Rough Creep Arse™
 
Transmogrify's Avatar
 
Join Date: Jul 2005
Location: Vancouver, Canada
Posts: 1,888
Send a message via MSN to Transmogrify
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8