SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    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" %>

  2. #2
    SitePoint Enthusiast
    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.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •