SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Non-Member
    Join Date
    Jul 2008
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Open in a new window with javascript

    Hello,

    I have an asp page to search for data. I like to open it in a new window while retain the search values. And I also can resize the window as well as set its attributes like
    height, width,etc.

    I created a js function like this:

    function posttopopup(formname, windowname)
    {
    if (! window.focus)return true;
    window.open('', windowname);
    formname.target=windowname;
    return true;
    }

    on my asp search page:

    <form method="post" action=search.asp" onSubmit="posttopopup(this, 'popupwindow')">
    .....
    <input type="button" name="Submit1" value="Search" onclick="if (isDate()) document.Search.submit();">

    I keep getting errors like "document.search has no value..."

    What did I do wrong?

    Thanks.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,717
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    The simple solution is to make the button a submit button, so that it automatically submits the form without you needing to make any special calls.

    If the function call results in a value that you don't like (returning false for not a date, for example), you can return that value to the onclick event to prevent the submit button from submitting the form.

    A simple way is this:

    Code html4strict:
    <input type="submit" name="Submit1" value="Search" onclick="if (isDate() === false) { return false; }">

    You can make it even simpler like this:

    Code html4strict:
    <input type="submit" name="Submit1" value="Search" onclick="return isDate();">
    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
  •