Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Opening a new window from a form

Posted by Chris_Isaac (Chris Isaac), 10 May 2006
Hi

Bit stuck at the moment, What I would like to do is open a new window when a button on a html form is pressed.  I've looked at window.open function in Javascript which I can get to work on its own, but can't implement it into my existing script.  Here is the bit of the existing script:

Code:
$other = ($row[active] > 0) ? "<form action=\"http://www.theaccommodationfinder.co.uk/sites/$row[hid].php4\" method=get>".
           "<input name=hid type=hidden value=".$row[hid].">".
           "<input type=submit value=\"Further details for $row[name]\"></form>     " : "";



Which basically displays a "Further information" button if the site is live, then opens a page relating to the hotel.

Not sure how to get Javascript to fit in there, any ideas please?

Thanks.

Posted by admin (Graham Ellis), 10 May 2006
Add  target=wname to your <form> tag if you want to target to a window called wname, or add target=_blank if you want to create a new window every time.

Posted by Chris_Isaac (Chris Isaac), 11 May 2006
Perfect.  Thanks.

Posted by Chris_Isaac (Chris Isaac), 13 May 2006
Sorry, another problem.  I didn't want any toolbars or address bars so I changed to the following:

Code:
     $other = ($row[active] > 0) ? "<form method=get onSubmit=\"window.open('http://www.theaccommodationfinder.co.uk/sites/$row[hid].php4?hid=$row[hid]' ,'', 'top=50, left=50, width=700, height=700, scrollbars')\">".
           "<input name=hid type=hidden value=".$row[hid].">".
           "<input type=submit value=\"Further details for $row[name]\">            
           
           </form>   " : "";



Which does exactly what I want, in terms of the child window, displays the information correctly without toolbars, etc.

The problem is when the form is submited it changes the main page, and I don;t know why.  The following link is what I'm taking about, if you hit the 'Further details' button you'll see what I mean:

http://www.webbreaks.co.uk/townsearch.php4?nexty=2&town=Newport&county=%20Gwent

Have I missed anything?

Thanks.

Posted by admin (Graham Ellis), 13 May 2006
In technical terms , the Javascript seems to be refreshing the current window with the same parameters as you pass to the new window too.  Alas, like you I can't see why and I don't know enough JavaScript to make an educated guess either, I'm afraid.   Chris - in your shoes I would continue testing, tweaking, breaking and refixing and then see if I could make some sense of what I had learnt!

Graham

Posted by Chris_Isaac (Chris Isaac), 13 May 2006
Funny enough I was just loging on to say I've found the same thing.  The main page's parameters are changing for some reason, been playing for a while but not quite got it yet...  I'll not let it beat me....  

Posted by Chris_Isaac (Chris Isaac), 14 May 2006
Done it.  

Changed the method to POST instead of get thats done the trick.  

Thanks for your help anyway.

Cheers.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2012: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho