473,549 Members | 2,948 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="JavaS cript" src="cal.js"></script><!-- Date only with
year scrolling -->
</head>
<BODY onLoad="showDet ails()">
<script language="javas cript">
function validatePage(){
return true;
}

function updateDetails() {
var basicStaffNoChe ck=false;
basicStaffNoChe ck=basicStaffVa lidation();
if(basicStaffNo Check)
{
var canSub = false;
if(validatePage ()){
with(document.f orms[0]){
if(hidDataChnge d.value!='1')
alert("No records updated. Please update atleast one record and
click OK");
else{

document.forms[0].btnSubmit.disa bled=true;
hidActionId.val ue="OK";
submit();

}
}
}
}
}
function showDetails(){

document.getEle mentById("Staff Number").focus( );

}

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

if(document.get ElementById('St affNumber').val ue == "")
{
alert("Please enter Staff Number");
document.getEle mentById('Staff Number').focus( );
}
if(document.get ElementById('St affNumber').val ue != "")
{
flag=validateSt affNo();
alert("returnin g from validateStaffNo "+flag);
if(flag)
{
document.forms[0].submit();
}
else
{
alert("Ïnside else");
return;
}
}
}


function validateStaffNo (){

var val = document.getEle mentById('Staff Number').value;

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

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

document.getEle mentById('Staff Number').focus( );
return false;

}
else
return true;

}

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

</script>
<FORM name="frmInvoic e" method="post" onsubmit="alert ('Why does it
submit');">
<input type="hidden" name="hidAction Id">
<!-- input type="hidden" name="hidPassId " -->
<input type="hidden" name="hidPassId Val">

<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="OraPromp tText"><LABEL>S taff
Number&nbsp;</LABEL></SPAN>
</TD>
<TD ><input id="StaffNumber " class="OraField Text" onchange=""
name="StaffNumb er" size="10" type="text" maxlength="6"
onKeyDown="KeyD ownHandler(Disp layDetails);">
</TD>
<TD width="15%"><in put type="button" id="DisplayDeta ils"
name="DisplayDe tails" value="Display Personal Details"
onClick="displa yError();">
</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 1885
"Gayathri" <Ga************ ****@gmail.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...

[snip]

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

function updateDetails() {
var basicStaffNoChe ck=false;
basicStaffNoChe ck=basicStaffVa lidation();
if(basicStaffNo Check)
{
var canSub = false;
if(validatePage ()){
with(document.f orms[0]){
if(hidDataChnge d.value!='1')
alert("No records updated. Please update atleast one record and
click OK");
else{

document.forms[0].btnSubmit.disa bled=true;
hidActionId.val ue="OK";
submit();

}
}
}
}
}
function showDetails(){

document.getEle mentById("Staff Number").focus( );

}

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

if(document.get ElementById('St affNumber').val ue == "")
{
alert("Please enter Staff Number");
document.getEle mentById('Staff Number').focus( );
}
if(document.get ElementById('St affNumber').val ue != "")
{
flag=validateSt affNo();
alert("returnin g from validateStaffNo "+flag);
if(flag)
{
document.forms[0].submit();
}
else
{
alert("Ïnside else");
return;
}
}
}


function validateStaffNo (){

var val = document.getEle mentById('Staff Number').value;

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

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

document.getEle mentById('Staff Number').focus( );
return false;

}
else
return true;

}

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

</script>
<FORM name="frmInvoic e" method="post" onsubmit="alert ('Why does it
submit');">
<input type="hidden" name="hidAction Id">
<!-- input type="hidden" name="hidPassId " -->
<input type="hidden" name="hidPassId Val">

<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="OraPromp tText"><LABEL>S taff
Number&nbsp;</LABEL></SPAN>
</TD>
<TD ><input id="StaffNumber " class="OraField Text" onchange=""
name="StaffNumb er" size="10" type="text" maxlength="6"
onKeyDown="KeyD ownHandler(Disp layDetails);">
</TD>
<TD width="15%"><in put type="button" id="DisplayDeta ils"
name="DisplayDe tails" value="Display Personal Details"
onClick="displa yError();">
</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="javas cript">
should be
<script type="text/javascript">

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

4) "basicStaffVali dation()" is referenced but not defined.

5) Why do you have: onchange=""

6) "hidDataChn ged" is misspelled and not defined.

7) Optimize your code; for example:

var basicStaffNoChe ck = false;
basicStaffNoChe ck = basicStaffValid ation();
if (basicStaffNoCh eck) {

could be just

if (basicStaffVali dation()) {

8) And finally,

it submits because the Enter key = a Submit button

Change "onsubmit=" to something like:

onsubmit="retur n 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
8664
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() { document.myform.submit(); }
3
11666
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 it by the document.form.submit() but this takes me through the validation attached with the submit twice( giving me all the alerts twice). ...
2
3102
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 is performed. How do I force the usercontrol to display the newly assigned date? I don't have this problem if I place the two dropdownlist and the...
3
1872
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 for argument sake). What happens when the form is submitted (when the submit button is clicked...) depends on some previous user input. In one case,...
5
77575
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 that or maybe blah blah or why do you wanna do that blah blah. I haven't seen a solution to this problem. OK, I am trying to share session objects...
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
4963
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 values seem to pass except what the submit buttons say. I have a preview button and a finish button, and need to check which was pressed. I can add a...
3
1701
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 <? $host="localhost"; // Host name. $db_user="****"; // MySQL username. $db_password="*******"; // MySQL password. $database="cms"; // Database...
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1936
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 we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.