SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Jun 5, 2008, 01:17 #1
- Join Date
- Jun 2008
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
function to check selected button
how to write this in proper javascript way;
function check_selected_button(){
if buttonA.clicked
open in a new window
else doNothing
}
<% submit_tag "ButtonA" %>
-
Jun 5, 2008, 02:30 #2
- Join Date
- Jun 2008
- Posts
- 41
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Add an onclick="" handler to the <submit> button with "window.open(url, name, params) return false;" call, or add an onsubmit handler to the <form> with the same code.
-
Jun 5, 2008, 18:20 #3
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
Please do not add event attributes to HTML. They may temporarily solve the issue but just like adding style attributes to your HTML, they wind up causing more pain in the long run.
Instead, use more traditional event registration techniques.
If you have a function that you wish to attach to an event, use the following
Code javascript:function doSomething() { // ... } var myForm = document.getElementsById('myForm'); myForm.onclick = doSomething;
If you have lines of code that you wish to attach to an event, use an anonymous function instead.
Code javascript:var myForm = document.getElementsById('myForm'); myForm.onclick = function () { // ... }
To place this in terms of the proposed answer, here is how it should be achieved.
Code javascript:var myForm = document.getElementsById('myForm'); myForm.onsubmit = function () { window.open('page.html', 'pageName', params); return false; }
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
Bookmarks