Monday, April 1, 2013

The simplest way I can guarantee What is the data entered by the user in a particular field in my HTML form?

Real question created by j p: What is the simplest way could I ensure that the user inputs data for specific fields in my html form?

With my current code, even if the user does not enter any information for “fullname” the data sent to my email address contains the Default Value (Full Name) instead of advising the user that some of the form has not yet been completed.


Here is my “required” code:


Here is a snippet of my form code.


Personal Information:


That may be interesting facts about What is the simplest way could I ensure that the user inputs data for specific fields in my html form? which you can would be smart to clear up situations for their own reasons. Eventually this element helps in lots of ways… and help your life significantly better. Who want interesting facts about What is the simplest way could I ensure that the user inputs data for specific fields in my html form? would be a cure down the road.

Solution:


Answer by Dinesh Reddy

Add some validation code to your full name text box.


Thanks,

Dinesh


Answer by Michael

The simplest would be to add a javascript function that checks that values have been set for the required items called from the forms onsubmit attribute as in the following.


However as perhaps 10% of visitors to your website may have javascript turned off, you should also perform the same check in your serverside script.


The following is a very simple validation script – it only checks that the input fields don’t have their default values. A more sophisticated script would also make some basic checks, such as minimum length for name and valid format for email address.


function validateForm(theForm) {

/* function to check that all required data entered on theForm */

var required = new Array(); /* the required input fields */

required = theForm.required.value.split(‘, ‘);

var message = ”; /* message to user */

/* for each required input filed check not defaultValue */

for (i = 0; i < required.length; i++) {

/* will only work for uniquely named inputs – ie not radiobuttons */

var theInput = document.getElementsByName( required[i] )[0];

if (theInput.value == theInput.defaultValue) {

message += "Please enter a value for " + theInput.defaultValue +".\n";

}

}

if (message == '') {

return true;

} else {

alert(message);

return false;

}

}


Learn better?

Add all your answer for the comments!


Watch more videos like this at http://teachparentstech.org.


lots of email


Appearance basically by lots of email


“A typical American office worker checks his email more than 50 times a day, sends or receives an instant message nearly 80 times a day and visits more than 40 different websites.”


Tim Shipman | New lifeline for staff drowning in emails | The Telegraph


www.telegraph.co.uk/digitallife/main.jhtml?xml=/connected…


Background image courtesy of genevievegood: www.flickr.com/photos/genevievegood/2042411328. This citation appears in the bottom left of the image.


The simplest way I can guarantee What is the data entered by the user in a particular field in my HTML form?

No comments:

Post a Comment

Blog Archive