Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2006, 12:14 PM   PM User | #1
skill_guy101
New Coder

 
Join Date: Feb 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
skill_guy101 is an unknown quantity at this point
Form Validation using getElementbyId

i have modifed a script by Stephen Poley and have got it to work correctly:
http://www.xs4all.nl/~sbpoley/webmatters/formval.html

However, i need the page to be in Strict XHTML 1.1 so i can't do <form name="contactform">. When i try and use the getElementbyId('name') instead of document.forms.contactform.name the script doesnt work.

what am i doing wrong?

Code:
<script type="text/javascript">
<!--
// Only script specific to this form goes here.
// General-purpose routines are in a separate file.
  function validateOnSubmit() {
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
    if (!ValidateOther(document.getElementbyId('name'), 'nameinfo'))        errs += 1;
    if (!validateEmail(document.getElementbyId('email'), 'emailinfo', true)) errs += 1; 
    if (!ValidateOther(document.getElementbyId('subject'), 'subjectinfo'))        errs += 1;
    if (!ValidateOther(document.getElementbyId('message'), 'messageinfo'))        errs += 1; 
    if (errs>1)  alert('There are fields which need correction before sending');
    if (errs==1) alert('There is a field which needs correction before sending');

    return (errs==0);
  };
// -->
</script>

<form onsubmit="return validateOnSubmit()" action="http://www.cems.uwe.ac.uk/~tdrewry/cgi/cgiform.cgi" method="post">

 <p>
   <label for="name">*Name:</label><br />
   <input type="text" name="name" id="name" onchange="ValidateOther(this, 'nameinfo');" />
   <label id="nameinfo">&nbsp;</label><br />
 </p>

 <p>
   <label for="email">*Email:</label><br />
   <input type="text" name="email" id="email" onchange="validateEmail(this, 'emailinfo', true);" />
   <label id="emailinfo">&nbsp;</label><br />
 </p>

 <p>
   <label for="subject">*Subject:</label><br />
   <input type="text" name="subject" id="subject" onchange="ValidateOther(this, 'subjectinfo');" />
   <label id="subjectinfo">&nbsp;</label><br />
 </p>

 <p>
   <label for="message">*Message:</label><br />
   <textarea name="message" id="message" onchange="ValidateOther(this, 'messageinfo');" cols="255" rows="9"></textarea>
   <label id="messageinfo">&nbsp;</label><br />
 </p>

 <p>
   <input type="submit" name="Submit" value="Send" />
 </p>

</form>
the whole page can be found here
skill_guy101 is offline   Reply With Quote
Old 03-13-2006, 10:25 PM   PM User | #2
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
In what way does it not work?
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 03-13-2006, 11:21 PM   PM User | #3
skill_guy101
New Coder

 
Join Date: Feb 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
skill_guy101 is an unknown quantity at this point
if you click on the link
http://www.thelogoarchive.com/dylan/contact.html and press send with invalid data it is suposed to pop up with a box saying "There are fields which need correction before sending".

if you save the file to your computer and change the getelimentbyid to forms.contact.*insert value such as name* and put a name=contact thing in the form tag it will work.

but strict xhtml 1.0 doesnt suport name inside a form tag.
skill_guy101 is offline   Reply With Quote
Old 03-13-2006, 11:41 PM   PM User | #4
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
JavaScript is case-sensitive.

There is no
Code:
document.getElementbyId()
you mean
Code:
document.getElementById()
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 03-14-2006, 12:13 AM   PM User | #5
skill_guy101
New Coder

 
Join Date: Feb 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
skill_guy101 is an unknown quantity at this point
ahh brilliant,

thanks
skill_guy101 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 12:20 PM.


Advertisement
Log in to turn off these ads.