473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

keeping to current page after form validation alert

Hi.

I have a multi-page form where the user enters datails to be submitted to a
database on the final page.

To move through the pages I have Next and Previous buttons using the
following function

function nextPage(loc) {
validateForm('section'); //checks for blank fields and displays an alert
box
location.href=loc +
generateSearchStringFromStore(store); //passes escaped data string made
up from the form entries
} //to the
location in the loc parameter.
This function is called when the Next button is clicked -

<img src="images/Next-button.gif" width="90" height="32" border="0"
align="absmiddle"
onClick="nextPage('page2.html')">

Thing is, blank fields cause validateForm to display an alert box, but when
the user clciks OK page2 is displayed.

I read that if you want to stop the next page loading you have to add the
validation function to the onSubmit listener, so I tried this

<form name="section" id="section" onSubmit="validateForm('section')">

and changed the button handler to this

<img src="images/Next-Button.gif" width="90" height="32" align="absmiddle"
onClick="document.section.submit();
location.href='page2.html' +
generateSearchStringFromStore(store)">

There are no errors reported but nothing at all happens: no alert box
reporting empty fields and page2 doesn't load.

Anyone know what I'm doing wrong?

I;ve seen examples where people write something like

onSubmit="return validateForm('section')"

so I also tried returning a false value from validateForm but nothing
happened then either.

Perplexed....
Jul 20 '05 #1
3 9405
When you call the function onsubmit - you are not telling the form when
not to submit

try

onSubmit="return validateForm('section')"

and add

return true/false

within the validation function

Hope this helps

Simon Christie

"Bill" <no@where.com> wrote in message
news:bn**********@hercules.btinternet.com...
Hi.

I have a multi-page form where the user enters datails to be submitted to a database on the final page.

To move through the pages I have Next and Previous buttons using the
following function

function nextPage(loc) {
validateForm('section'); //checks for blank fields and displays an alert box
location.href=loc +
generateSearchStringFromStore(store); //passes escaped data string made up from the form entries
} //to the
location in the loc parameter.
This function is called when the Next button is clicked -

<img src="images/Next-button.gif" width="90" height="32" border="0"
align="absmiddle"
onClick="nextPage('page2.html')">

Thing is, blank fields cause validateForm to display an alert box, but when the user clciks OK page2 is displayed.

I read that if you want to stop the next page loading you have to add the
validation function to the onSubmit listener, so I tried this

<form name="section" id="section" onSubmit="validateForm('section')">

and changed the button handler to this

<img src="images/Next-Button.gif" width="90" height="32" align="absmiddle"
onClick="document.section.submit();
location.href='page2.html' +
generateSearchStringFromStore(store)">

There are no errors reported but nothing at all happens: no alert box
reporting empty fields and page2 doesn't load.

Anyone know what I'm doing wrong?

I;ve seen examples where people write something like

onSubmit="return validateForm('section')"

so I also tried returning a false value from validateForm but nothing
happened then either.

Perplexed....

Jul 20 '05 #2
Actually, all I did was

function nextPage(loc) {
if (validateForm('section')) {
updateStoreFromForm('section', store);
location.href=loc +
generateSearchStringFromStore(store);
}
}

and it worked :oP

But anyway, what you're saying is that onSubmit="return
validateForm('section')" will stop the submit if the function returns
false, and will allow the submit if true is returned?

I tried something like that earlier but must have mucked it up somehow - but
that's why people put a return in there....?

Thanks.
"steve stevo" <st***@stevosteve.fsnet.co.uk> wrote in message
news:bn**********@news8.svr.pol.co.uk...
When you call the function onsubmit - you are not telling the form when
not to submit

try

onSubmit="return validateForm('section')"

and add

return true/false

within the validation function

Hope this helps

Simon Christie

"Bill" <no@where.com> wrote in message
news:bn**********@hercules.btinternet.com...
Hi.

I have a multi-page form where the user enters datails to be submitted to
a
database on the final page.

To move through the pages I have Next and Previous buttons using the
following function

function nextPage(loc) {
validateForm('section'); //checks for blank fields and displays an

alert
box
location.href=loc +
generateSearchStringFromStore(store); //passes escaped data string

made
up from the form entries
} //to

the location in the loc parameter.
This function is called when the Next button is clicked -

<img src="images/Next-button.gif" width="90" height="32" border="0"
align="absmiddle"
onClick="nextPage('page2.html')">

Thing is, blank fields cause validateForm to display an alert box, but

when
the user clciks OK page2 is displayed.

I read that if you want to stop the next page loading you have to add the validation function to the onSubmit listener, so I tried this

<form name="section" id="section" onSubmit="validateForm('section')">

and changed the button handler to this

<img src="images/Next-Button.gif" width="90" height="32" align="absmiddle" onClick="document.section.submit();
location.href='page2.html' +
generateSearchStringFromStore(store)">

There are no errors reported but nothing at all happens: no alert box
reporting empty fields and page2 doesn't load.

Anyone know what I'm doing wrong?

I;ve seen examples where people write something like

onSubmit="return validateForm('section')"

so I also tried returning a false value from validateForm but nothing
happened then either.

Perplexed....


Jul 20 '05 #3
Bill wrote:
But anyway, what you're saying is that onSubmit="return
validateForm('section')" will stop the submit if the function returns
false, and will allow the submit if true is returned?
Yes, if JavaScript is supported.
[...] that's why people put a return in there....?
Yes.
[Fullquote]


Please don't make top postings, thanks.
PointedEars

Jul 20 '05 #4

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

Similar topics

6
by: Abby Lee | last post by:
I have a for statement in my validation process I do a for loop becasue I don't know how many rows of items there are...I need to validate each item in each row. If I remove the...
13
by: s_m_b | last post by:
I'm building a suite of online forms for insurance. These have been stripped down from messy MS Word templates, and two of the six, substantially identical, are misbehaving with the .js page that...
10
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> ...
2
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> ...
1
by: Liz | last post by:
I have a page with several dropdownlists, several text boxes and several buttons which perform calculations. I need to validate one dropdownlist (not the whole page) with the click of one button. I...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
8
by: M.L. | last post by:
Hello. I created a form using JS validation with the form tag as follows: <form name="form1" action="dynaform.php" method="post" onsubmit="return pvg_sub();"> The js validation script sends...
3
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
16
by: sreemati | last post by:
Hi everyone, This is the scenario: I have two button - Submit and Reset Submit is used for validation and after validation is passed it passes it to another form to enter into database. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
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...

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.