HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 8th, 2004, 06:35 AM
rufus rufus is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 rufus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 51 sec
Reputation Power: 0
Detect Which button was pressed in Javascript

I have two submit buttons on a form which both call the same function onsubmit of the form.

I would like to know in the function which button I pressed.

Here is the pseudo code I have so far

function Validate(form)
{

//What is syntax here??
if (form.submitButton.pressed==true){

return true;
}
//What is syntax here??
if (form.clearButton.pressed==true){

return false;
}

}

Thanks

Reply With Quote
  #2  
Old November 8th, 2004, 06:38 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,936 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 11 h 28 m
Reputation Power: 1537
this is not ASP question rather Javascript question - this post should be in the html/javascript forum.
anyways, this is quite simple:
if (window.event.srcElement == form.submitButton)
//code to handle submit button click...

the window.event.srcElement returns the "source object", i.e. the object which raised the current event. in your case, it will be the button which caused the Validate() function to fire.

Reply With Quote
  #3  
Old November 8th, 2004, 06:59 AM
rufus rufus is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 rufus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 51 sec
Reputation Power: 0
Thanks for your reply.

Unfortunately I don't think you have understood my query.

It is not the buttons which call the Validate function.

It is the asp page form which runs the validate function. (Hence why I posted the query in this forum.)
i.e.
<form action="simpleform.asp" method="post" name="form1" onsubmit="return Validate(this);" >

<input type="submit" name="action" value="Submit" />
<input type="submit" name="clear" value="Clear All"/>

So in your example window.event.srcElement will always be form1. ( I think)

I need to know which of two submit buttons was pressed last (or has gotfocus or something like that)

I hope this clarifys things a bit more and thanks again.

Reply With Quote
  #4  
Old November 8th, 2004, 07:20 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,936 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 11 h 28 m
Reputation Power: 1537
no you're wrong.
please try the code I've given and let me know how it goes.

Reply With Quote
  #5  
Old November 8th, 2004, 09:10 AM
rufus rufus is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 rufus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 51 sec
Reputation Power: 0
I'm afraid I still stick by what I have said.

When I alert out window.event.srcElement.name in the validate function it always
gives me form1 and not the button names.

Although I'm not very good at asp/javascript this makes perfect sense to given that
the srcElement detects the thing which calls the function.

In my example as you can see it is the form onsubmit which calls the validate function. (NOT the the submit and clear buttons.)

Nevertheless I have overcome my initial problem of knowing which button was last pressed by adding a onclick event on each of the buttons which set a variable value in the javascript.

Thanks for all your help. Appreciate it.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Detect Which button was pressed in Javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway