Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions Calling In JavaScript Functions from HTML Form To Validate User Entered Data
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Mike Lee
Calling In JavaScript Functions from HTML Form To Validate User Entered Data
0 Answer(s)      a year and 9 months ago
Posted in : JavaScript Questions


Hello, I have been working for days on my web Form assignment and editing my html to call my functions to validate the user entered data, but to no avail.I finally decided to place the functions in the head. But, I still cannot make a call. Below is my code. Please help. Thanks in advance.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Subscription Form</title>
<script type="text/javascript">
function validateSubscriptionForm () {
    //declare variables to check if textfields are blank
    var blankEmail=chkEmail ();
    var blankFname=chkFN ();
    var blankLname=chklN ();
    var blankAddr=chkAddr ();
    var blankCity=chkCity ();
    var blankSt=chkSt ();
    var blankZipCode=chkZ ();
    var blankTel=chkTel ();
}

function chkEmail (){
    if (document.Subscription_Form.getElementById("eMailTextField").value == "") {
        alert("Please fill in required e-mail address");
        document.Subscription_Form.eMailTextField.focus();//repositions the cursor back to the email textfield
        }
}

function chkFN () {
    if (document.Subscription_Form.getElementById("firstNameTextField").value == "")    {
        alert("Please fill in required First Name");
        document.Subscription_Form.firstNameTextField.focus();
        }       
}

function chklN (){
    if (document.getElementById("lastNameTextField").value == "")   {
        alert("Please fill in required Last Name");
        document.Subscription_Form.lastNameTextField.focus();
        }
}

function chkAddr (){
    if (document.getElementById("addressTextField").value == "")    {
        alert("Please fill in required Address");
        document.Subsciption_Form.addressTextField.focus();
        }
}

function chkCity() {
    if (document.getElementById("cityTextField").value == "")   {
        alert("Please fill in required City");
        document.Subscription_Form.cityTextField.focus();
        }
}

function chkSt () {
    if (document.getElementById("stateTextField").value == "")  {
        alert("Please fill in required State");
        document.Subscription_Form.stateTextField.focus();
        }
}

function chkZ (){
    if (document.getElementById("zipCodeTextField").value == "")    {
        alert("Please fill in required Zip Code");
        document.Subscription_Form.zipCodeTextField.focus();
        }
    if (isNaN(zipCodeTextField.value) == true) {
    alert("Please enter a valid Zip Code Number");
    zipCodeTextField.focus();
    zipCodeTextField.select();
    }   
}

function chkTel () {
    if (document.getElementById("telephoneTextField").value == "")  {
        alert("Please fill in required Telephone");
        document.Subscription_Form.telephoneTextField.focus();
        }
}
</script>
<link href="form_style_1.css" rel="stylesheet" title="Subscription Form Style 1" type="text/css" />
<!--create script to link this subscription form to the acknowledgement page -->
</head>

<body>
<!--insert form and design form layout with a header -->
<form name="Subscription_Form" action="" method="post"  id="form1"><!--form1 sets style of subscription form-->
<h1>Subscription Form</h1>
<p align="center">The <span style="color:#F00">*</span> denotes required information</p>
<p>
    <label><span style="color:#F00"> * </span> Email: </label>
    <input style="position:absolute; left: 116px;" type="text" size="30" align="right" id="eMailTextField" onclick="chkEmail()" /><br />
    </p>
<p> 
    <label><span style="color:#F00"> * </span> First Name: </label>
    <input style="position:absolute; left: 116px;" type="text" size="30" align="right" id="firstNameTextField" /><br />
</p>
<p>  
    <label><span style="color:#F00"> * </span> Last Name: </label>
    <input style="position:absolute; left: 116px;" type="text" size="30" align="right" id="lastNameTextField" /><br />
</p>
<p>  
    <label><span style="color:#F00"> * </span> Address: </label>
    <input style="position:absolute; left: 116px;"  type="text" size="30" align="right" id="addressTextField" /><br />
</p>
<p>    
    <label><span style="color:#F00"> * </span> City: </label>
    <input style="position:absolute; left: 115px;" id="cityTextField" type="text" size="30" maxlength="30" /><br  />
</p>
<p>  
    <label><span style="color:#F00"> * </span> State: </label>
    <input style="position:absolute; left: 116px;" type="text" size="2" maxlength="2" align="right" id="stateTextField" /><br />
</p>
<p>
    <label><span style="color:#F00"> * </span> Zip Code: </label>
    <input style="position:absolute; left: 116px;" type="text" size="5" maxlength="5" align="right" id="zipCodeTextField" /><br />
</p>

<p> 
    <label><span style="color:#F00"> * </span> Telephone: </label>
    <input style="position:absolute; left: 116px;" type="text" size="30" maxlength="30" align="right" id="telephoneTextField" /><br  />
</p>

<input style="position:absolute; left: 188px;" type="submit" value="Submit" onclick="validateSusbscriptionForm()" />

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Calling In JavaScript Functions from HTML Form To Validate User Entered Data
Calling In JavaScript Functions from HTML Form To Validate User Entered Data  Hello, I have been working for days on my web Form assignment and editing my html to call my functions to validate the user entered data
calling java method from html form with out using javascript - JSP-Servlet
calling java method from html form with out using javascript  How can i call java method from a HTML form, java script should be disabled?  ...;script LANGUAGE="JavaScript">function testResults(form
Advertisements
How to display user entered information using HTML and JavaScript
How to display user entered information using HTML and JavaScript. We are going to describe How to display user entered information using HTML and JavaScript. First of all we have created HTML form with two text fields "
Sending form data from HTML page to SQLserver 2005 database by calling servlet code
Sending form data from HTML page to SQLserver 2005 database by calling servlet code  Hi sir, I would like to know how to send the form data from html page to database by calling servlet code from html page .   
validating a form before data is entered.
validating a form before data is entered.  How can I avoid validating a form before data is entered
to store data entered in html page
to store data entered in html page  i want to a job site, in this site user can registered by a form.. in this form there are his information... i... submit we have to move to form 2 on there we have enter text data
How do i validate form using javascript and send data to database?
How do i validate form using javascript and send data to database?  I need a "JOIN US" form that can validate using javascript and be able to connect with and post data into a database. The details to be validated and posted
HTML Form data into .CSV?
HTML Form data into .CSV?  how to store data from html form to csvfile in java
JavaScript User Defined Functions
JavaScript User-Defined Functions: An user-defined function saves  us... them to work. JavaScript has so many built-in functions, besides  that you can make your own as per the need. General structure of the user defined
Restricting the user from filling the data in a textfield using html
Restricting the user from filling the data in a textfield using html  I got a requirement like this, If the user is trying to fill a text field, i have to restrict him
how to pass form values from javascript of html page to jsp page
how to pass form values from javascript of html page to jsp page   This is my sample html page which contains inline javascript which calculates... to submit all the form values with lattitude and longitude returned from
how to send smtp mail to entered user mail id after user registered using javascript?
how to send smtp mail to entered user mail id after user registered using javascript?  how to send smtp mail to entered user mail id after user registered using javascript
how to send smtp mail to entered user mail id after user registered using javascript?
how to send smtp mail to entered user mail id after user registered using javascript?  how to send smtp mail to entered user mail id after user registered using javascript
Process HTML FORM data
Process HTML FORM data  Can a JSP page process HTML FORM data?   Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick
How to store data entered by User in JSP page in XML file
How to store data entered by User in JSP page in XML file  How to store data entered by user in JSP page to be saved in XML file.On clicking submit button data entered by a user in a page must be saved in XML file.How to do so
Calling java class method from javascript
Calling java class method from javascript  I want to call a java class method from javascript. The java class method is like "public String[] getWord()". I want to assign this string array value to a variable in javascript. I
write a javascript progam to implement functions in html
write a javascript progam to implement functions in html  write a javascript progam to implement functions in html  Please visit the following link: http://www.roseindia.net/javascript/emailvalidation.shtml http
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page
How to store data entered in JSP page by a user in XML file & later retrieval... file.How can i store data entered by user in XML file and later retrieve data... by user to be stored in xml file.here you have entered data in JSP file
how to validate the telephone number without using jquery in html with javascript
how to validate the telephone number without using jquery in html with javascript  how to validate the telephone number without using jquery in html with javascript
display data from database in textbox when id entered in textbox
display data from database in textbox when id entered in textbox  i wanted to enter data in textbox .depending on entered data in textbox data from database should be displayed dynamically in textbox
how to display data from database according to entered value in search field
how to display data from database according to entered value in search..."); if(data != "bmi_value"){ %> <script language="javascript">..., so i want the data of user who have 17 as their bmi value to appear. help me
extract data from HTML
extract data from HTML  how to write the coding for to extract data from html tags like(h3,p) and then extracted data should be stored in data base? can anybody tell me how to write the coding
Hi how to transfer table data from html page to excel sheet by using javascript .
Hi how to transfer table data from html page to excel sheet by using javascript .  html page to excel sheet by using javascript and i dont want to transfer all rows in table, i want to hide some rows in excel sheet. Please send
Html form using JavaScript to display the table content
Html form using JavaScript to display the table content  HI There, Greetings, I am new to this java and I need your assistance. I have created... want to write a Html JavaScript coding to display the content from database
How to hide HTML code from user? - Security
How to hide HTML code from user?  Hi All, I am trying to provide security to my web application. To achieve this I want to restrict user from... through the use of DOM loading the data from another javascript file
calling a javascript function by passing multiple values from applet in web application
calling a javascript function by passing multiple values from applet in web application  Hi all, I have a requirement like this, I have to call a javascript function from JApplet by passing 3 values. I am new to Applets
PHP HTML Form Submit Button
in Html is used to submit form data to the page mentioned in the ACTION attribute... values from the text box in the Html form...Topic : HTML FORM SUBMIT BUTTON Part - 4 The another part which is important
JSP to add details to a database from a HTML form.
JSP to add details to a database from a HTML form.  Hi I'm a second year CS student who has to use JSP to validate a HTML form and add the details... from form and stores it in User--%> String Pword = request.getParameter
How to Validate dynamically created text box in HTML using Javascript
How to Validate dynamically created text box in HTML using Javascript  Here is the HTML code to create text boxes dynamically. It works properly.... And also how to validate the text boxes created dynamically. <html>
Calling Action on form load - Struts
; This action needs no data other than the user's session, which it can get from...Calling Action on form load  Hi all, is it possible to call... this list is coming from the action which i m calling before the page is being
fetch data from database in javascript
fetch data from database in javascript   How to fetch data from database in JavaScript when it is a leap year
 

 

 

DMCA.com