473,385 Members | 1,730 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,385 software developers and data experts.

Prompt to submit

I have a form that the user can edit data in. However, there are a couple
of links on the page. The user can edit the data and click on a link, not
submitting the form.

Is there some code out there that will check to see if they changed the
form, and prompt them to submit it if they try to exit the page any other
way?

Perfect example:
www.windowsupdate.com
Using IE, scan for updates, then click "personalize windows update". Change
something on that list, then try to navigate away.

Matthew

Jul 20 '05 #1
6 4217
Matthew wrote:

I have a form that the user can edit data in. However, there are a couple
of links on the page. The user can edit the data and click on a link, not
submitting the form.

Is there some code out there that will check to see if they changed the
form, and prompt them to submit it if they try to exit the page any other
way?

Perfect example:
www.windowsupdate.com
Using IE, scan for updates, then click "personalize windows update". Change
something on that list, then try to navigate away.

Matthew


Matthew,

You can use the onUnload event in combination with some form checks
which check the current value of the form fields against the default
values.
Not secure, not foolproof (you can easily turn off javascript), but it
will allow you to do what you ask.

Gr, J.
Jul 20 '05 #2
Thanks.

This is just for my customers convenience; no "security" necessary.

Matthew

Jul 20 '05 #3
Below is the code I wrote.

It seems to work properly. As I am a bit new to JavaScript, can somebody
take a look at the logic for inefficiencies?

I don't know a better way to do "function nocheck".

Also, is there a quick, easy way to submit the form "cart", then continue to
where they wanted to go originally?

Thanks for the help.

Matthew

Code:

<HEAD>
<script type="text/JavaScript">
<!--

function nocheck() {
changeform = nothing
}

function nothing(){
}

function changeform() {
if (checkform())
{
return true
} else {
var confirmed = confirm("You have changed the quantity of an item.\nClick
OK to save your changes.");
if (confirmed == true) {
document.cart.submit();
return false
} else {
return true
}
return false
}
}

function checkform() {
if (document.cart.qty01.value != 8)
{
return false
}
if (document.cart.qty02.value != 7)
{
return false
}
if (document.cart.qty03.value != 6)
{
return false
}
if (document.cart.qty04.value != 4)
{
return false
}
return true
}
//-->
</script>
</HEAD>
<BODY onUnload="changeform();">
<FORM method="post" name="cart" action="test.htm" onSubmit="nocheck();">

some code

</FORM>

some links

</BODY>

Jul 20 '05 #4
JRS: In article <x9*****************@fe01.usenetserver.com>, seen in
news:comp.lang.javascript, Matthew <tu*************@alltel.net> posted
at Tue, 3 Feb 2004 19:37:46 :-

function changeform() {
if (checkform())
{
return true
} else {
var confirmed = confirm("You have changed the quantity of an item.\nClick
OK to save your changes.");
if (confirmed == true) {
document.cart.submit();
return false
} else {
return true
}
return false
}
}


function changeform() {
if (checkform()) return true // else not needed after return
var confirmed = confirm("You have changed the quantity of an item." +
"\nClick OK to save your changes.");
if (confirmed) document.cart.submit() // ==true is normally pointless
return !confirmed }

I split the string in order to for News convention of margin 72; code
should NEVER be wrapped by a system that does not understand it.

The return statement is an EXIT statement; not like Result in Delphi,
which is a variable that can be accessed repeatedly.

While else is perfectly legal, nested else becomes hard to read. Some
teach that functions should only be exited at their ends; my view is
that their exits should be obvious - so the early return could be
commented // EARLY RETURN.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #5
Thanks for looking at the code.

It looks much cleaner.

Matthew

Jul 20 '05 #6
JRS: In article <x9*****************@fe01.usenetserver.com>, seen in
news:comp.lang.javascript, Matthew <tu*************@alltel.net> posted
at Tue, 3 Feb 2004 19:37:46 :-
function checkform() {
if (document.cart.qty01.value != 8)
{
return false
}
if (document.cart.qty02.value != 7)
{
return false
}
if (document.cart.qty03.value != 6)
{
return false
}
if (document.cart.qty04.value != 4)
{
return false
}
return true
}

The following should be equivalent; but it seems a strange need :

function checkform() { return (
document.cart.qty01.value == 8 &&
document.cart.qty02.value == 7 &&
document.cart.qty03.value == 6 &&
document.cart.qty04.value == 4 ) }

function checkform() { with (document.cart) return (
qty01.value == 8 && qty02.value == 7 &&
qty03.value == 6 && qty04.value == 4 ) }


To turn off checking by function X, use global G

function X() {
if (G) return true // or false
<series-of-tests> }

function X() {
return G || <series-of-tests> }

function X() {
return G && <series-of-tests> }

The first and second return true if G is true; the third returns false
if G is false; in each case, without further tests. I think.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #7

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

Similar topics

7
by: Petesman | last post by:
I am trying to make a prompt that will ask the user for some input... If I just use var input = prompt("dafa") everything works fine but the box is put in the top left corner of the window. I need...
3
by: vijay21 | last post by:
hi all, Can we restrict the number of characters that the user can input in a javascript prompt? my browser hangs whenever i try to input more than 2048 characters in it. Thanks for any help
1
by: Rezas | last post by:
Hello I am using a html file type to prompt for a file path, but it is losing the value after a submit or in case of a submit? Is there another server component that does this more efficiently Or...
3
by: J.P. Cummins | last post by:
In my ASP.NET application, I wish to have a page for administrators to edit items in a list. Preferably, I would like to use the javascript prompt for the 'rename' function, and a javascript alert...
3
by: Sheau Wei | last post by:
i would like to create a prompt up messsage in when submit a form, how to make it?
1
by: andwing | last post by:
<form method="post" name="folder" id="folder"> <input type="hidden" name="name" value="" /> <input name="submit" type="hidden" value="new name .." onclick="getname();" /> function getname () {...
1
by: TokyoJ | last post by:
I use a popup / prompt requesting the visitor to enter a USERNAME so after the user clicks SUBMIT on the prompt all the pages in the site should greet the user with Hi, USERNAME. But there are two...
4
by: Geoff Cox | last post by:
Hello, Very odd this? I have a form which has <input name="Submit" type="Submit" value="Click to send _ when finished" onclick="getName()"> and
1
by: ramprakashjava | last post by:
hi , i hav this error while running this customerDetails.jsp <html:html> <head> <html:base/> </head> <body> <html:errors/> <html:form...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.