SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript open new window

    Im doing a simple search in my app something like below;
    Last edited by rambo1; Jun 9, 2008 at 20:01. Reason: no

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Code javascript:
    document.getElementsByName('commit')[1].onclick = function () {
    	var equipment = window.open('generate.html', 'generate');
    	return false;
    };
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the quick reply..But i still can get it to work. Im new to javascript so i have no idea what you code all about. Can you explain a bit and where im suppose to put the code?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    The code should appear after the form elements are on the page. The best place to put it is at the end of the body, just before the </body>

    The document.getElementsByName('commit')[1] gets a list of all the named elements called 'commit' and because [0] is the first one in the list, [1] ensures that we take the second submit button called commit.

    An improved way to do that would be to give them unique names, or to provide an identifier for the submit button itself. So you could have:

    Code html4strict:
    <form action="/equipment" method="get">
    <input type="submit" name="commit" id="performSearch" value="Search" />
    <input type="submit" name="commit" id="generateSearch" value="Generate" />

    Code javascript:
    document.getElementsById('generateSearch').onclick = function () {
        var window.equipment = window.open('generate.html', 'generate');
        return false;
    };

    When the generate button is clicked, it'll open a window whose content comes from generate.html
    On the main page, you will be able to access that generate window through the equipment variable
    Last edited by paul_wilkins; Jun 10, 2008 at 13:39.
    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
  •