www.webdeveloper.com
Results 1 to 2 of 2

Thread: question about form submission scripting.

  1. #1
    Join Date
    Sep 2012
    Posts
    1

    question about form submission scripting.

    first off i'm a student i was in a web development class and I have a question about using scripts in a form.

    it took me a while to get but i finally got the validation to work so it will allow for a dialog bow if something is not entered but i want to get it another to pop up if everything is entered and is able to send. i'm not looking for a real validation to check check to see if the email is valid or anything like. i'm just trying to figure out how exactly this stuff works because i'm having a hard time grasping the syntax for some of this. here is the code that is need help with.

    <script>
    function validate()
    {
    var vText1=trim(document.frm.sText1.value);
    var vText2=trim(document.frm.sText2.value);
    var vText3=trim(document.frm.sText3.value);

    if(vText1=="")
    {
    alert("Please specify email address");
    document.frm.sText1.focus();
    return false;
    }
    else if(vText2, vText3=="")
    {
    alert("First and last name are required.");
    document.frm.sText2.focus();
    return false;
    }
    }

    function trim(s) {
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
    }

    </script>
    </head>
    <body>
    <center><form name="frm" method="post" action="mailto: myemail@email.com" onsubmit="return validate ()">
    Email:<input name="sText1" type="text" size="26"/>
    <br/>
    First:<input name="sText2" type="text" Size="27" maxlength="15" />
    <br />
    Last:<input name="sText3" type="text" size="28" maxlength="20" />
    <br />
    <textarea name="email" cols="45" rows="5" maxlength="500">Please keep all emails 500 words or less</textarea><br />
    <input name="Submit" type="submit" value="Send Email" /></form></center><br />
    </BODY>
    </HTML>

    what is killing me on this is trying to figure out what is needed to get the alert for the final if else i've tried several different things but all end up causing the code to fail. so i'm not sure what i need to do to make it pop up and that the email was sent based solely on the fact that text has been entered in all 3 boxes.

  2. #2
    Join Date
    Jul 2011
    Posts
    127
    For getting alert to the final if else first and last names should not be blank. So it will be something like this:
    Code:
    function validate()
    {
        var vText1=trim(document.frm.sText1.value);
        var vText2=trim(document.frm.sText2.value);
        var vText3=trim(document.frm.sText3.value);
    	 
        if (vText1 && vText2 && vText3) {
            alert("Form is ready to submit");
            return true;
        }
    
        if(vText1=="")
        {
            alert("Please specify email address");
            document.frm.sText1.focus();
        }
        else if(!(vText2 && vText3))
        {
            alert("First and last name are required.");
            document.frm.sText2.focus();
        }
        return false;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles