Help - Search - Members - Calendar
Full Version: form validation with java problem!
HTMLHelp Forums > Programming > Client-side Scripting
jason95
Hey there,
I have a slight problem with a contact form for my website,I added the form validation script to the top of my form,so when I am using notepad and enter input fields and submit, the blocker pops down warning of a script access.Once I allow the access warning my validation "you must enter firstname" and so on work fine.
My validation wont work when users try to use the contact form?
Here is the full html code and java added in. Thanks for any info! wacko.gif
jason95
QUOTE(jason95 @ Apr 1 2011, 07:02 AM) *

Hey there,
I have a slight problem with a contact form for my website,I added the form validation script to the top of my form,so when I am using notepad and enter input fields and submit, the blocker pops down warning of a script access.Once I allow the access warning my validation "you must enter firstname" and so on work fine.
My validation wont work when users try to use the contact form?
Here is the full html code and java added in. Thanks for any info! wacko.gif

<html>
<head>
<title>JavaScript Form Validation Script</title>
<script language="JavaScript" type="text/JavaScript">

function checkForm(thisform)
{
if(thisform.Firstname.value=='')
{
alert("Firstname field is required. Please fill it in.");
return false;
}
if(thisform.Lastname.value=='')
{
alert("Lastname field is required. Please fill it in.");
return false;
}
if(thisform.Address.value=='')
{
alert("Address field is required. Please fill it in.");
return false;
}
if(thisform.Email.value=='')
{
alert("Email field is required. Please fill it in.");
return false;
}
//if all is OK submit the form

thisform.submit();
}
</script>
<body>
<form name="form1" id="form1" method="post" action="--SCRIPT.PHP--">
<table width="400px" border="0px" bgcolor="#ffffff" cellpadding="2" cellspacing="2">
<tr><td width="150px" align="left">
<strong>Firstname:</td>
<td align="left" ><input name="Firstname" type="text" id="Firstname" size="15"
style="color: #000000;
font-family: Verdana; font-weight: bold; font-size:
14px; background-color: #FFE4B5;" /></td>
</tr>
<tr>
<td><strong>Lastname:</td>
<td><input name="Lastname" type="text" id="Lastname" size="15"
style="color: #000000;
font-family: Verdana; font-weight: bold; font-size:
14px; background-color: #FFE4B5;" /></td>
</tr>
<tr>
<td><strong>Address:</td>
<td><input name="Address" type="text" id="Address" size="30"
style="color: #000000;
font-family: Verdana; font-weight: bold; font-size:
14px; background-color: #FFE4B5;" /></td>
</tr>
<tr>
<td><strong>Email:</td>
<td><input name="Email" type="text" id="Email" size="25"
style="color: #000000;
font-family: Verdana; font-weight: bold; font-size:
14px; background-color: #FFE4B5;" /></td>

<td><input name="Submit" type="button" id="Submit" onclick="checkForm(this.form)" value="Submit" /></td>

wacko.gif


Christian J
QUOTE(jason95 @ Apr 1 2011, 02:02 PM) *

when I am using notepad and enter input fields and submit, the blocker pops down warning of a script access.Once I allow the access warning my validation "you must enter firstname" and so on work fine.

Sounds like http://www.phdcc.com/xpsp2.htm --if so it only affects javascript on your offline pages.

When you write "notepad", did you actually mean the computer keyboard? Otherwise you lost me. unsure.gif
jason95
[/quote]
Sounds like http://www.phdcc.com/xpsp2.htm --if so it only affects javascript on your offline pages.

When you write "notepad", did you actually mean the computer keyboard? Otherwise you lost me. unsure.gif
[/quote]

"Keyboard indeed" thanks for response, so the problem wont show up once site is online if I understand
correctly! Also I entered the form code, <form name="form1" id="form1" method="post" action="--SCRIPT.PHP--"> into the top of the contact form
and validation, but where do I enter the <FORM action="form2.php" method="post"> to send it to the php file for processing?

Darin McGrew
QUOTE
Here is the full html code and java added in.
And for the record, it's JavaScript, not Java. They are completely different languages, and the similarity in their names is just a confusing marketing decision.
jason95
QUOTE(Darin McGrew @ Apr 1 2011, 12:45 PM) *

QUOTE
Here is the full html code and java added in.
And for the record, it's JavaScript, not Java. They are completely different languages, and the similarity in their names is just a confusing marketing decision.

was to lazy to write java...... hahaha anywho thanks for info biggrin.gif
pandy
QUOTE(jason95 @ Apr 1 2011, 04:30 PM) *

Also I entered the form code, <form name="form1" id="form1" method="post" action="--SCRIPT.PHP--"> into the top of the contact form
and validation, but where do I enter the <FORM action="form2.php" method="post"> to send it to the php file for processing?


You should have the URL to the script as the value for 'action' in the only start tag for FORM you are allowed to have. "--SCRIPT.PHP--" is mumbo jumbo. Replace it with the real URL.

Note, you can have several forms on the same page, but each form consists of only one FORM element, so you can't have two start tags for FORM in the same form.
Christian J
The current form can't be submitted if javascript is unsupported. That can actually be used as a way to stop spambots, but then there should at least be some kind of message for honest users without javascript.

To avoid javascript-dependency you can use a real submit button an call the javascript from an onsubmit event in the FORM element, like in this example: http://www.w3schools.com/js/js_form_validation.asp
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.