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

Need Javascript Advice

Hi All,

Here is my situation: I have a form where the user can perform a
number of tasks. One of these tasks is to enter a new record. The
form has an 'onsubmit' property to validate the data if the users
enters a new record.

However, there is also a button to allow the user to 'duplicate' a
stored record. In that case, I do not want to perform the entire
validation since most of the data will be fetched from the database
behind the scene. But, when the form submits, the 'onsubmit' property
takes off and attempts to validate the form......

What is the best way to handle this? Basically different behaviors
when the form is submitted??

I'm not a good Javascript programmer, so explaining throughly would
really help.

Thanks,

Arthur

Jan 18 '06 #1
1 1337
am****@iwc.net wrote:
Here is my situation: I have a form where the user can perform a
number of tasks. One of these tasks is to enter a new record. The
form has an 'onsubmit' property to validate the data if the users
enters a new record.
Actually, the `form' element has an intrinsic event handler attribute
for handling its `submit' event, named `onsubmit'.
However, there is also a button to allow the user to 'duplicate' a
stored record. In that case, I do not want to perform the entire
validation since most of the data will be fetched from the database
behind the scene. But, when the form submits, the 'onsubmit'
property takes off and attempts to validate the form......

What is the best way to handle this? Basically different behaviors
when the form is submitted??


You need to find out which submit button was activated. The following
example should be self-explaining:

<script type="text/javascript">
function validate(f)
{
if (f && arguments.callee.submit.name != "duplicate")
{
// perform validation, return `false' if the result is negative
}

return true;
}
validate.submit = {};
</script>

<form ... onsubmit="return validate(this);">
...
<input type="submit" value="Submit"
onclick="validate.submit = this;">
<input type="submit" name="duplicate" value="Duplicate"
onclick="validate.submit = this;">
</form>
HTH

PointedEars
Jan 18 '06 #2

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

Similar topics

8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
4
by: Marquisha | last post by:
If this is off-topic, please forgive me. But I thought this might be the perfect spot to get some advice about how to proceed with a project. Working on a Web site design for a nonprofit...
8
by: Andrew Phillipo | last post by:
I have a layout which works perfectly. It is three column, the central column is width:auto; with margins and the columns are absolutely positioned at top:0px; left:0px; and top:0px;right:0px; ...
4
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all...
9
by: optimistx | last post by:
Which url in your opinion would be a good or even the best example of javascript usage in a set of pages at least say 10 or more pages? How to use css, how to split js-code to files, how to code...
1
by: Ben | last post by:
Hi, I come from classic asp and i need some advice for this application. It's about a computer reservation system in a school. I want a page where a student can see his own made reservations,...
9
by: mistral | last post by:
Need help to remove list of days from date script. Need format "June 07, 2006" <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Get today's current date. var now = new Date();
8
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
10
by: mark4asp | last post by:
I ask this because only today I read advice telling me to put it within the <headelement. This is the same advice I've always been given but no one ever explained why. Last week I was told to...
25
by: Oltmans | last post by:
Hi guys, I'm learning JavaScript and I need some puzzles that can make me a better JavaScript programmer. I mean I'm looking out for programming puzzles (e.g. Project Euler or TopCoder) but I'm...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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: 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...

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.