473,545 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript onClick question


Hi,

We have a form defined with buttons like this:

<a class="save_men u" href="javascrip t:document.Deta il_Screen.actio n =
'savedata.php?s creen=EDIT';doc ument.Detail_Sc reen.submit();" >Update</
a>

The form also has an onSubmit action to vall a validation routine:

<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>

The problem is that the formvalidation routine is not being fired.

I'm at a loss here. Can anyone help us with this? At the end of the
javascript validation routine, we have this:

thisform.submit ();

So, the form seems to submit, but not the way we want it to. We want
it to execute the validation routine first.....

Thank you.

John.
Jun 27 '08 #1
14 2162
<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>

The problem is that the formvalidation routine is not being fired.

I'm at a loss here. Can anyone help us with this? At the end of the
javascript validation routine, we have this:

thisform.submit ();
formvalidation should return TRUE or FALSE, depending on whether the
form's content is valid, or not.

If that doesn't help, please provide a more detailed code sample; an
ideal example would be a URL to a page demonstrating the problem
Jun 27 '08 #2
On Jun 1, 4:31 pm, Mtek <m...@mtekusa.c omwrote:
Hi,

We have a form defined with buttons like this:

<a class="save_men u" href="javascrip t:document.Deta il_Screen.actio n =
'savedata.php?s creen=EDIT';doc ument.Detail_Sc reen.submit();" >Update</
a>
Why are you using an anchor element to submit a form? A submit input
or button would be the appropriate choice and works with JavaScript
disabled.
The form also has an onSubmit action to vall a validation routine:

<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>
Single quotation marks around attribute values are not valid.
The problem is that the formvalidation routine is not being fired.

I'm at a loss here. Can anyone help us with this? At the end of the
javascript validation routine, we have this:

thisform.submit ();
remove that
So, the form seems to submit, but not the way we want it to. We want
it to execute the validation routine first.....
How about something straight forward like this

<form name="Detail_Sc reen" action="savedat a.php"
method="post" onsubmit="retur n formvalidation( this);">

<input type="submit" name="screen" value="EDIT">
</form>

If you really must have a link trigger the form submission then you
can do that but it seems very odd.

Peter
Jun 27 '08 #3
On Jun 1, 4:53 pm, Dan Rumney <danrum...@warp mail.netwrote:
<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>
The problem is that the formvalidation routine is not being fired.
I'm at a loss here. Can anyone help us with this? At the end of the
javascript validation routine, we have this:
thisform.submit ();

formvalidation should return TRUE or FALSE, depending on whether the
form's content is valid, or not.
JavaScript will type convert the return value of the onsubmit handler
to be a boolean. That type converted value will be used to determine
if the form should be submitted or not.
If that doesn't help, please provide a more detailed code sample; an
ideal example would be a URL to a page demonstrating the problem
Where that page is self-complete and only 30 to 40 lines long.

Peter
Jun 27 '08 #4
On Jun 1, 7:12*pm, Peter Michaux <petermich...@g mail.comwrote:
On Jun 1, 4:53 pm, Dan Rumney <danrum...@warp mail.netwrote:
<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>
The problem is that the formvalidation routine is not being fired.
I'm at a loss here. *Can anyone help us with this? *At the end of the
javascript validation routine, we have this:
thisform.submit ();
formvalidation should return TRUE or FALSE, depending on whether the
form's content is valid, or not.

JavaScript will type convert the return value of the onsubmit handler
to be a boolean. That type converted value will be used to determine
if the form should be submitted or not.
If that doesn't help, please provide a more detailed code sample; an
ideal example would be a URL to a page demonstrating the problem

Where that page is self-complete and only 30 to 40 lines long.

Peter

Well, the client wants the inmage button. And, as you can see, it is
not really an image, but a class. That is what they want, so that is
how I have to code it. The page submits and the data is saved, it
just does not call the javascript validation routine. That is where
my issue is.......

Making it a SUBMIT will not work since it is not a 'real' button.
Here is a clip of the code:

<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>
.
.
<table class="menu" cellspacing=0>
<TR>
<td class="menu1">< a class="save_men u"
href="javascrip t:document.Deta il_Screen.actio n = 'savedata.php?
screen=EDIT';do cument.Detail_S creen.submit(); ">Update</a></td>
<td style="width:1p x"><img src="../images/admin2/
separator_27h.g if"></td>
<td class="menu1">< a class="save_men u"
href="javascrip t:document.Deta il_Screen.actio n = 'savedata.php?
screen=DELETE'; document.Detail _Screen.submit( );">Delete</a></td>
<td style="width:1p x"><img src="../images/admin2/
separator_27h.g if"></td>
</tr>
</table>
.
.
</FORM>

Thanks for everyone's help so far.....

John
Jun 27 '08 #5
Making it a SUBMIT will not work since it is not a 'real' button.
Here is a clip of the code:

<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>
.
.
Can you provide the source for 'formvalidation '?
Jun 27 '08 #6
On Jun 1, 8:54*pm, Dan Rumney <danrum...@7761 7270mail.netwro te:
Making it a SUBMIT will not work since it is not a 'real' button.
Here is a clip of the code:
<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>
.
.

Can you provide the source for 'formvalidation '?

Here you go, and thanks!!

function formvalidation( thisform) {
if (emptyvalidatio n(thisform.Cust Name.value,"Cus tomer Name is
empty")==false) {thisform.CustN ame.focus(); return false;};
if (emailvalidatio n(thisform.Cust Email.value,"Il legal E-
mail")==false) {thisform.CustE mail.focus(); return false;};

if (thisform.CellP hone.value==nul l || thisform.CellPh one.value==""
|| thisform.CellPh one.value==" ") {
thisform.CellPh one.value="000-000-0000";
} else {
if (phonevalidatio n(thisform.Cell Phone.value,"Pl ease enter a
valid cell phone")==false) {
thisform.CellPh one.focus(); return false;
};
};
thisform.submit ();
}
Jun 27 '08 #7
On Jun 1, 6:46 pm, Mtek <m...@mtekusa.c omwrote:
On Jun 1, 7:12 pm, Peter Michaux <petermich...@g mail.comwrote:
On Jun 1, 4:53 pm, Dan Rumney <danrum...@warp mail.netwrote:
<FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='retur n formvalidation( this)'>
The problem is that the formvalidation routine is not being fired.
I'm at a loss here. Can anyone help us with this? At the end of the
javascript validation routine, we have this:
thisform.submit ();
formvalidation should return TRUE or FALSE, depending on whether the
form's content is valid, or not.
JavaScript will type convert the return value of the onsubmit handler
to be a boolean. That type converted value will be used to determine
if the form should be submitted or not.
If that doesn't help, please provide a more detailed code sample; an
ideal example would be a URL to a page demonstrating the problem
Where that page is self-complete and only 30 to 40 lines long.
Peter

Well, the client wants the inmage button. And, as you can see, it is
not really an image, but a class. That is what they want, so that is
how I have to code it.
You can style a <button type="submit"el ement.

Peter
Jun 27 '08 #8
On Jun 1, 9:49*pm, Dan Rumney <danrum...@7761 7270mail.netwro te:
Here you go, and thanks!!
function formvalidation( thisform) {
* * if (emptyvalidatio n(thisform.Cust Name.value,"Cus tomer Name is
empty")==false) {thisform.CustN ame.focus(); return false;};
* * if (emailvalidatio n(thisform.Cust Email.value,"Il legal E-
mail")==false) {thisform.CustE mail.focus(); return false;};
* * if (thisform.CellP hone.value==nul l || thisform.CellPh one.value==""
|| thisform.CellPh one.value==" ") {
* * * *thisform.CellP hone.value="000-000-0000";
* * } else {
* * * *if (phonevalidatio n(thisform.Cell Phone.value,"Pl ease enter a
valid cell phone")==false) {
* * * * * thisform.CellPh one.focus(); return false;
* * * *};
* * };
* * thisform.submit ();
}

Change "thisform.submi t()" to "return true"

However, Reading you original post again, you wrote:

*<a class="save_men u"
*>
href="javascrip t:document.Deta il_Screen.actio n='savedata.php ?screen=EDIT';
** * document.Detail _Screen.submit( );">Update</>a>

[snip]

*At the end of the javascript validation routine, we have this:
*>
*thisform.submi t();
*>
*So, the form seems to submit, but not the way we want it to. *We want
*it to execute the validation routine first.

So, I think you're saying "Why isn't validation performed when the user
clicks on Update?"

So, I believe this is an accurate description of what's happening. I've
looked for something to back it up, but all I can find are unreferenced
comments on the web.

The onSubmit Event Handler is is used to execute specified JavaScript
code whenever the *user* submits a form.

I believe the problem you have is that Javascript aclling the submit()
function is *not* the same as the user submitting the form. Thus the
onSubmit handler is not invoked.

In fact, this is why you calling submit() in your onSubmit handler does
not cause an infinite loop.

The resolution would be an explicit call to formvalidation( )
... something like:

<a class="save_men u"
href="javascrip t:document.Deta il_Screen.actio n='savedata.php ?screen=EDIT';
formvalidation( document.Detail _Screen) &&
document.Detail _Screen.submit( );">Update</>a>- Hide quoted text -

- Show quoted text -

Hi Dan,

Your suggestion seems to work. I had to change a few things. But
when I submit the form, it something fails the validation, it gives
the proper error message, but then a new page appears with only the
word 'false' on it........

On another note, I do not understand why sometimes I can refer to a
parameter by name, and other times I need parameter.value .........

Thanks again!!!

John
Jun 27 '08 #9
Peter Michaux wrote:
On Jun 1, 4:53 pm, Dan Rumney <danrum...@warp mail.netwrote:
>><FORM name='Detail_Sc reen' action="savedat a.php" METHOD="POST"
onsubmit='ret urn formvalidation( this)'>
The problem is that the formvalidation routine is not being fired.
I'm at a loss here. Can anyone help us with this? At the end of the
javascript validation routine, we have this:
thisform.subm it();
formvalidati on should return TRUE or FALSE, depending on whether the
form's content is valid, or not.

JavaScript will type convert the return value of the onsubmit handler
to be a boolean. [...]
How would you know?
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Jun 27 '08 #10

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

Similar topics

5
2185
by: Lucian Sandor | last post by:
Hello everyone, While I'm a newbie here, I a not new to google, so please don't send me back, it would be useless. First of all I have to specify I am working on a Blogger.com template, therefore anything I'll write should be stuck on a single file. I thought about creating a funny pop-up. <a href="javascript:myFunction();"... that's...
2
1447
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select one of three answers for each question, and automatically assign a value to their answer ("never"=0, "sometimes"=1, "always"=2). There would be...
0
6419
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to be modified: if(e.CommandName =="Print") { string parsedreceipt = null; parsedreceipt = DecodeReceipt (e.Item.Cells.Text); Session =...
8
3633
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
7
8916
by: Papelotte | last post by:
Hi all, I'm new to this forum and I am hoping that there is someone here who can help me. I have an ASP page that has javascript that works perfectly in IE, but not in Firefox. Can anybody tell me how to get it to work in FF. I can insert a browser identifier and redirect if the script has to change for FF only. Basically, when a vistor...
8
4016
by: rn5a | last post by:
I have gone through a no. of posts in this NewsGroup regarding my problem but alas, couldn't come across one which would have helped me in resolving the issue. My problem is this: An ASPX Form has a Button. When the Button is clicked, I want a JavaScript confirm dialog to pop-up with the options 'OK' & 'Cancel'. I have done this using the...
16
1898
by: Tony Girgenti | last post by:
Hello. I just finished reading two articles about javascript here: http://msdn2.microsoft.com/en-us/library/bb332123(VS.80).aspx I tried some javascript testing in VS2005, SP1, VB , .NET 2.0, ASP.NET 2.0 on WIN XP Pro, SP2. It's real simple. I put a button on a page and coded the onClick in it like this:
11
2009
by: nitha | last post by:
hi there...i need help... just wondering how to put a function? this is the form: <form> <p>Room type:<br/> <input type="radio" id="room1" name="room" onclick="roomCost=150" value="150"/><label for="garden">Garden</label><br/> <input type="radio" id="room2" name="room" onclick="roomCost=200" value="200"/><label...
1
2057
by: Van Dugall | last post by:
Hello I have been writing a game in javascript which works fine but I wanted to step it up and request the data of the game from the server. I haven't really used php...all I know is from the Internet and I couldn't really find the answer I was looking for. I asked around and they said this is really easy to implement but I still can't get it to...
0
7420
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
7680
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
7934
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...
0
6003
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
5349
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
4966
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
3476
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
1908
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
731
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.