Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2011, 03:53 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to get var string to alert..NEWBIE

i have written a script with the help of Java 24 hr trainer but now need to add some other function and cant figure out how to go about it.
Im am validating form fields and then would like to return the fields in a prompt box after validation is complete and as a final display on screen and also to get user to confirm details are correct before final submit is activated.
how do i go about this correctly? i think i need to set up another function that gets a string of varibles that have been input by user and prompt them.

i know the code is unruly but its my first attempt.
i presume this is incredibly basic for you people .any help greatly appreciated.
code is as follows

javascript Code:
function validateForm(event) {                        //assign function id
    var form1 = document.form1;                         //assign varibles
    var first = form1.first;
    var last = form1.last;
    var age = form1.age;
    var email = form1.email;
    var state = form1.state;
    var button = form1.btnSubmit;
    var textAge = parseInt(age.value);
 
    // validate first name field
    if (!isEmpty(first.value)) {

        // valiidate last name field
        if (!isEmpty(last.value)) {

            // validate email field
            if (email.value.indexOf("@") > 0 ) {

                //validate age field
                if (!isNaN(textAge) && textAge >=18) {

                //alert messages when conditions are true
              } else {
                alert("Please enter your age, you must be over 18");
                age.focus();
                age.select();
              }
             
             } else {
                alert("Please enter a valid email address");
                email.focus();
                email.select();
             }
                   
        } else {
            alert("Please enter your last name");
            last.focus();
            last.select();
        }

    } else {
        alert("Please enter your first name");
        first.focus();
        first.select();
    }

 }
 //to determine if a value is empty
function isEmpty(value) {
return (value === "");
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie (very newbie!) question about com.paad.* jkcashin BOOK: Professional Android 2 Application Development 3 June 5th, 2013 06:52 AM
var as variable incredi-man Javascript 2 September 16th, 2006 11:46 AM
Using a var into the name of another var or field. guizero Access VBA 3 May 30th, 2006 03:47 PM
newbie question- cutting a string apart harpua BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 June 21st, 2005 04:53 AM
newbie - Query to String dholcomb Access VBA 3 August 16th, 2004 09:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.