473,549 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript to indicate form content has been edited?

Hi All,

I'm wondering if anyone can point me to some JavaScript code I can
drop into a page to respond to an attempt to click on specific links
if content in textarea on a form has been changed but not submitted?

In essence, if someone starts editing content in a textarea on the
form, then clicks on one of several specific links, I'd like a box to
come up asking them if they want to lose their edits or submit the
form first.

Any help will be much appreciated!

Much warmth,

Murray
http://www.planetthoughtful.org
Building a thoughtful planet,
one snide comment at a time...
Jul 23 '05 #1
3 1698
M Wells wrote:
Hi All,

I'm wondering if anyone can point me to some JavaScript code I can
drop into a page to respond to an attempt to click on specific links
if content in textarea on a form has been changed but not submitted?

In essence, if someone starts editing content in a textarea on the
form, then clicks on one of several specific links, I'd like a box to
come up asking them if they want to lose their edits or submit the
form first.


Presumably, the user enters some text to the text area and submits the
form. You return a page with the text area and the submitted text
inside it.

If the user edits the submitted text, you want to know about it. Is
that right?

Put a copy of the submitted/returned text into a hidden text area:

<textarea ... style="display: none;" ...>the submitted text</textarea>

Then compare the text in the displayed textarea with the hidden one
when the user submits the form a second time. You can add one for each
control you want to check on - make sure you deal with special
characters properly when comparing the textarea values.

Fred.
Jul 23 '05 #2
M Wells wrote:
I'm wondering if anyone can point me to some JavaScript code I can
drop into a page to respond to an attempt to click on specific links
if content in textarea on a form has been changed but not submitted?


In my functions at http://www.javascripttoolbox.com/validations/ there is a
function called "isFormModified " which checks a form for any changes from
when it was initially loaded.

So then you could do,

<a href="newpage.h tml" onClick="if(isF ormModified(doc ument.forms[0])){return
confirm('Form has been changed! Are you sure you want to leave the
page?');}else{r eturn true;}">Link</a>

(not tested, change form reference as necessary, beware of line wrap)

Hope that helps,

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #3
M Wells wrote:
Hi All,

I'm wondering if anyone can point me to some JavaScript code I can
drop into a page to respond to an attempt to click on specific links
if content in textarea on a form has been changed but not submitted?


Use the onchange event handler of the textarea to set a flag variable.
Use the onclick of the links to check that variable:

<textarea onchange="hasCh anged=true">
<a href="..." onclick="if(has Change)........ ">

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #4

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

Similar topics

136
9214
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to...
0
2165
by: Keith | last post by:
I have a web form that contains a repeater control that is designed to ask like a check book register. Clicking on a certain transaction takes the user to a different .aspx page where it can be edited and then saved. Currently, after saving the edited transaction and returning to the check register, the repeater control table returns to the...
0
1877
by: Keith | last post by:
I have a web form that contains a repeater control that is designed to ask like a check book register. Clicking on a certain transaction takes the user to a different .aspx page where it can be edited and then saved. Currently, after saving the edited transaction and returning to the check register, the repeater control table returns to the...
0
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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
6043
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...
0
5088
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1941
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
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.