638 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
RobbyDesigns says

I have two simple forms on a web page I’m making – both HTML (not PHP ).

The first form is a simple javascript password gate that sends the user to the next page if their password is correct. The second form is a contact form.

Both forms have their own ‘ID’.

I’m using a simple validation javascript to make sure the contact form has been filled in:

function setFocus(aField) { document.forms0.focus(); }

function isAnEmailAddress(aTextField) {

if (document.forms0.value.length<5) { return false; } else if (document.forms0.value.indexOf(”@”) < 1) { return false; } else if (document.forms0.value.length - document.forms0.value.indexOf(”@”) < 4) { return false; } else { return true; } }

function isEmpty(aTextField) { if ((document.forms0.value.length==0) || (document.forms0.value==null)) { return true; } else { return false; } }

function validate() {

if (isEmpty(“name”)) { alert(“Please fill in your Name.”); setFocus(“name”); return false; }

if (isEmpty(“email”)) { alert(“Please fill in your Email address.”); setFocus(“email”); return false; }

if (isEmpty(“comment”)) { alert(“Please fill in your message.”); setFocus(“comment”); return false; }

if (!isAnEmailAddress(“email”)) { alert(“The entered email address is invalid.”); setFocus(“email”); return false; }

return true;

}

The problem is this – the two forms + vlaidation script simply wont work together; I have to either delete the first form (the password gate) or go without the contact form.

Any ideas?

3323 posts
  • Provided great contribution to our forums
  • Nominated Community Superstar of the month
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
+18 more
dtbaker Moderator says
Any ideas?

Post a link to the problem page, the code here is all screwey.

638 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
RobbyDesigns says
Any ideas?
Post a link to the problem page, the code here is all screwey.

Thanks for your time – I’ve upped it to: http://www.robbydesigns.com/temp

You’ll see that the simple ‘login’ form reads a javascript to see if the correct answer has been given, if not it takes the viewer to ‘incorrect.html’.

The trouble is, the main contact form has it’s own javascript that checks the fields have been filled in; that wont work as long as the login form (see above) is on the page – if I delete the login form it works fine. IE I cant have 2 forms on 1 page.

426 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
vasilios says

I think it’s because you’re writing document.forms[‘0’]. That’s only targeting the first form on the page. For the first form you would write document.form[‘0’] and for the second one it would be document.forms[‘1’]. The form indexes start at zero because JavaScript’s arrays are zero based. :)

...unless I’m not understanding you.

3323 posts
  • Provided great contribution to our forums
  • Nominated Community Superstar of the month
  • Helps us moderate the forums
  • Has been part of the Envato Community for over 5 years
+18 more
dtbaker Moderator says

Yup try the [1] thing, if that doesn’t work try getElementById instead:


function isAnEmailAddress(aTextField) {

if(typeof document.getElementById(aTextField) != "undefined"){
    if(document.getElementById(aTextField).value.length<5){
        return false;
    }else if(document.getElementById(aTextField).value.indexOf("@ ") < 1){
        return false;
    }else if(document.getElementById(aTextField).value.length - document.forms[0][aTextField].value.indexOf("@ ") < 4){
        return false;
    }else{
        return true;
    }
    return false; // cant find email field..
}



remove space in that @ thing, the commenting system turns that whole block of code into an email address link without..

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by