SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    existing window changes into php result, when need to stay the same

    Hi there, i would appreciate it so much if somebody could please help me, i have been struggling on this problem for ages and i am not able to resolve it.

    i have 1 html file (main page) this files has 4 forms, each form 1 after the other. the separte forms on the main page are used to post data to php files via text boxes and submit button.
    for example i have a php file called availablewards, which takes the input from the html file and performs a query inregards to the input given and displays the result of the query.
    the html file is like this
    <form name ="ward" method= "post" action="availablewards.php" >
    this form all so has a submit button that opens up the availablewards.php when clicked on opens the php file in separate window.
    <input type="submit" value="Find ward" onclick="window.open('http://localhost/availableward.php')"

    however the problem is the new window that opens does not show the query result, it shows blank. the result is diplayed in the main window, main window changes loction to availableward.php. i need for the main window to stay the same and for the query result to show in the newly opened window when the submit button is clicked on.

    All help is appreciated. thank you

  2. #2
    SitePoint Wizard bronze trophy Centauri's Avatar
    Join Date
    May 2007
    Location
    Newcastle, Australia
    Posts
    3,718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would say the window.open function needs to be the action and not an onclick event, so <form name ="ward" method= "post" action="window.open('availableward.php')" >

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, Centauri, but that won't work. The action attribute requires an HTTP URI. You can't send an HTTP POST request to a JavaScript function. According to the spec,
    User agent behavior for a value other than an HTTP URI is undefined.
    If you want the action URI to open in a separate window, you can use the target attribute on the form, although that means you'll have to use a Transitional doctype.

    Another option is to do something similar to what you're already doing, but append all the form's field names and values as query parameters at the end of the URI to window.open(). You'd have to use JavaScript to do that, of course, and your PHP script may have to be modified to accept GET requests instead of POSTs. It would also be better to have this behaviour in the onsubmit handler for the form, rather than the onclick handler for the button.

    If you need to use POST and still want a pop-up window, you'll probably have to resort to an Ajax solution.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Wizard bronze trophy Centauri's Avatar
    Join Date
    May 2007
    Location
    Newcastle, Australia
    Posts
    3,718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    Sorry, Centauri, but that won't work. The action attribute requires an HTTP URI. You can't send an HTTP POST request to a JavaScript function. According to the spec,
    Oops ... I guess the "action" property is not very well named then

    Thanks Tommy, I learned something else new.


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
  •