When posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.
Also, please show only the
relevant code.
var x=document.forms["myForm"]["address"].value
if (x==null || x==""){
Form validation of the pattern if (document.formname.formfield.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe.
Numeric values, such as zip codes and phone numbers, should be validated as such. Ditto email addresses.
This topic has been covered many times before in this forum.
I think your requirement to be 18 to order adult books is pointless - any 13-year old will have the wit to enter a DOB which is over 18. (Note that the 18 calculation is wrongly based on birth-year only).
Code:
var y1 = date1.getFullYear(); //getting current year
var y2 = date2.getFullYear(); //getting dob year
var age = y1 - y2; //calculating age NO!
But your code should be
Code:
var int=document.getElementById("myForm").interest.value; // don't use the same name for an HTML element and a Javascript variable.
if (age < 18 && int=="2") {
alert('Your age is under 18 and you have ordered an Adult Book. Sorry you are not able to purchase Adult Books. Please choose Childrens Books');
}
Use the search feature of this forum to get a proper check valid date function. And email validator. Your code is 20th century stuff.
You are trying to use mailto as the form action.
The trouble with using this long-obsolete method (mailto) to send form results is its unpredictability. The method it is highly dependent on the browser in use
and the email client in use (some people have only Yahoo, Gmail or Hotmail). In particular, your visitor must have Outlook or Outlook Express or Windows Live Mail as the default client for this to work correctly. Even if your visitor is using Internet Explorer, but the default mail client is different (e.g. Eudora or Thunderbird), your mailto form will not work. With all of the browser troubles, you're likely to lose about half of your users' messages. Most of the email clients that can successfully
send a mail will prompt the user with a somewhat threatening security dialog prior to sending - this can scare many users from continuing. Other users will not wish to reveal their email address. Also, what about people with Javascript disabled?
In addition, if you place an unobfuscated email address in your webpage, the bots will quickly find it and inundate you in spam.
Modern browsers no longer accept mailto: as a form action - they simply open the email program (if any) and ignore the form. If you are going to use a form then use a server-side CGI formmail script as the action - there are several good free ones out there.
For a simple PHP form feedback script see:-
http://www.thesitewizard.com/archive/feedbackphp.shtml
or
http://www.felgall.com/php2.htm
I don't want to sound discouraging but your code could really do with a substantial re-work. There are many infelicities, example
x1 = x.replace(/[^a-z]/gi,""); // strip non-alpha chars
But you never use x1 and in any case a name may contain space hyphen apostrophe (surely not & ?)
If you are 20 and you are not a socialist, then you have no heart. If you are 40 and you are still a socialist, then you have no brain.