473,503 Members | 12,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does the form submit?

Please find the pasted html,
<html>
<script language="JavaScript" src="cal.js"></script><!-- Date only with
year scrolling -->
</head>
<BODY onLoad="showDetails()">
<script language="javascript">
function validatePage(){
return true;
}

function updateDetails(){
var basicStaffNoCheck=false;
basicStaffNoCheck=basicStaffValidation();
if(basicStaffNoCheck)
{
var canSub = false;
if(validatePage()){
with(document.forms[0]){
if(hidDataChnged.value!='1')
alert("No records updated. Please update atleast one record and
click OK");
else{

document.forms[0].btnSubmit.disabled=true;
hidActionId.value="OK";
submit();

}
}
}
}
}
function showDetails(){

document.getElementById("StaffNumber").focus();

}

function displayError()
{
alert("displayError");

if(document.getElementById('StaffNumber').value == "")
{
alert("Please enter Staff Number");
document.getElementById('StaffNumber').focus();
}
if(document.getElementById('StaffNumber').value != "")
{
flag=validateStaffNo();
alert("returning from validateStaffNo "+flag);
if(flag)
{
document.forms[0].submit();
}
else
{
alert("Ïnside else");
return;
}
}
}


function validateStaffNo(){

var val = document.getElementById('StaffNumber').value;

var patternBasic = new RegExp("^[0-9]{6}"); //matches alphanumeric
atleast 6 characters
var result = patternBasic.test(val);

if(!result)
{
alert("Alert 1 Please Enter a valid Staff Number.Please enter leading
zeroes if applicable.");

document.getElementById('StaffNumber').focus();
return false;

}
else
return true;

}

function KeyDownHandler(Btn)
{
if (event.keyCode == 13)
{
Btn.click();
}
}

</script>
<FORM name="frmInvoice" method="post" onsubmit="alert('Why does it
submit');">
<input type="hidden" name="hidActionId">
<!-- input type="hidden" name="hidPassId" -->
<input type="hidden" name="hidPassIdVal">

<br>
<TABLE width="80%" summary="" border="0" cellspacing="0"
cellpadding="0">
<TR>
<TD align="right" nowrap>
</TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD width="30%" height="3"></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD align="right" nowrap><span class="OraPromptText"><LABEL>Staff
Number&nbsp;</LABEL></SPAN>
</TD>
<TD ><input id="StaffNumber" class="OraFieldText" onchange=""
name="StaffNumber" size="10" type="text" maxlength="6"
onKeyDown="KeyDownHandler(DisplayDetails);">
</TD>
<TD width="15%"><input type="button" id="DisplayDetails"
name="DisplayDetails" value="Display Personal Details"
onClick="displayError();">
</TD>

</TR>
</TABLE>

</form>
</body>

</html>
Staff No is validated to be exactly 6 digits numeric.
On click of the "display personal details" button with the mouse,The
page behaves fine.But on hit of ENTER...after entering some three or
four digits in the staff No text box.Its validating and giving the
error message" Alert 1 Please Enter a valid Staff Number.Please enter
leading zeroes if applicable." Then form submits.On submit alert is
fired.
I dont want the submit to happen when the client validation
fails.Strangely the submit does not happen on click of the button using
mouse.Çan anybody help me please.

Dec 7 '05 #1
2 1872
"Gayathri" <Ga****************@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...

[snip]

Please find the pasted html,
<html>
<script language="JavaScript" src="cal.js"></script><!-- Date only with
year scrolling -->
</head>
<BODY onLoad="showDetails()">
<script language="javascript">
function validatePage(){
return true;
}

function updateDetails(){
var basicStaffNoCheck=false;
basicStaffNoCheck=basicStaffValidation();
if(basicStaffNoCheck)
{
var canSub = false;
if(validatePage()){
with(document.forms[0]){
if(hidDataChnged.value!='1')
alert("No records updated. Please update atleast one record and
click OK");
else{

document.forms[0].btnSubmit.disabled=true;
hidActionId.value="OK";
submit();

}
}
}
}
}
function showDetails(){

document.getElementById("StaffNumber").focus();

}

function displayError()
{
alert("displayError");

if(document.getElementById('StaffNumber').value == "")
{
alert("Please enter Staff Number");
document.getElementById('StaffNumber').focus();
}
if(document.getElementById('StaffNumber').value != "")
{
flag=validateStaffNo();
alert("returning from validateStaffNo "+flag);
if(flag)
{
document.forms[0].submit();
}
else
{
alert("Ïnside else");
return;
}
}
}


function validateStaffNo(){

var val = document.getElementById('StaffNumber').value;

var patternBasic = new RegExp("^[0-9]{6}"); //matches alphanumeric
atleast 6 characters
var result = patternBasic.test(val);

if(!result)
{
alert("Alert 1 Please Enter a valid Staff Number.Please enter leading
zeroes if applicable.");

document.getElementById('StaffNumber').focus();
return false;

}
else
return true;

}

function KeyDownHandler(Btn)
{
if (event.keyCode == 13)
{
Btn.click();
}
}

</script>
<FORM name="frmInvoice" method="post" onsubmit="alert('Why does it
submit');">
<input type="hidden" name="hidActionId">
<!-- input type="hidden" name="hidPassId" -->
<input type="hidden" name="hidPassIdVal">

<br>
<TABLE width="80%" summary="" border="0" cellspacing="0"
cellpadding="0">
<TR>
<TD align="right" nowrap>
</TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD width="30%" height="3"></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD align="right" nowrap><span class="OraPromptText"><LABEL>Staff
Number&nbsp;</LABEL></SPAN>
</TD>
<TD ><input id="StaffNumber" class="OraFieldText" onchange=""
name="StaffNumber" size="10" type="text" maxlength="6"
onKeyDown="KeyDownHandler(DisplayDetails);">
</TD>
<TD width="15%"><input type="button" id="DisplayDetails"
name="DisplayDetails" value="Display Personal Details"
onClick="displayError();">
</TD>

</TR>
</TABLE>

</form>
</body>

</html>
Staff No is validated to be exactly 6 digits numeric.
On click of the "display personal details" button with the mouse,The
page behaves fine.But on hit of ENTER...after entering some three or
four digits in the staff No text box.Its validating and giving the
error message" Alert 1 Please Enter a valid Staff Number.Please enter
leading zeroes if applicable." Then form submits.On submit alert is
fired.
I dont want the submit to happen when the client validation
fails.Strangely the submit does not happen on click of the button using
mouse.Çan anybody help me please.
[snip]
Where to start....!

1) No <head> tag

2) <script language="javascript">
should be
<script type="text/javascript">

3) "function updateDetails()" is defined but not referenced.

4) "basicStaffValidation()" is referenced but not defined.

5) Why do you have: onchange=""

6) "hidDataChnged" is misspelled and not defined.

7) Optimize your code; for example:

var basicStaffNoCheck = false;
basicStaffNoCheck = basicStaffValidation();
if (basicStaffNoCheck) {

could be just

if (basicStaffValidation()) {

8) And finally,

it submits because the Enter key = a Submit button

Change "onsubmit=" to something like:

onsubmit="return validateStaffNo()"

Good luck.
Dec 7 '05 #2
Thanks for the help.Really Thanks...I was in a hurry yesterday.Your
comments on code improvement is really a lot helpful.

Many thanks once again for formatting

Dec 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8653
by: Jason Novotny | last post by:
Hi, I'm trying to create a listbox using <select> HTML tags that can do a form submit when an option in the list is selected. So far this works, function MySelectSubmit() {...
3
11662
by: Megha Vishwanath | last post by:
Hi, I have a struts form <html:form> in which although the focus rests on the submit button, hitting the enter key does not submit the form. I tried capturing the Enter key event and followed...
2
3100
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
3
1867
by: Taras_96 | last post by:
Hi everyone, I've got a rather unconventional architecture that I'm having problems with... I have a form called "searchForm", that has an input of type "submit" (with name = "submitButton...
5
77542
by: antonyliu2002 | last post by:
Hi, It looks like so many people are having problems with the javascript submit in firefox. I searched around, but haven't found a solution yet. Mostly, people were saying, try this or try...
5
1638
by: Ted Ngo | last post by:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { txtSource.Focus(); frmMain.Visible = true; divWait.Visible = false; btnsubmit.Visible = true;
4
4957
by: d3vkit | last post by:
I have a form on my page, and some javascript which uses ajax to submit the form, and then opens the new page in a div using ajax so there is no refresh. This works fine. But the problem is this: all...
3
1695
tolkienarda
by: tolkienarda | last post by:
hi all i have a problem i have a script that i got working exactly the way i wanted it. and then i tried to intrigate it into the site and it totaly stopped working. below is the original code ...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.