Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:12

Running Javascript inside a <FORM> tag for menu link


Poster: careyadkins
Dated: Monday September 15 2003 - 17:55:58 BST

Here is what I currently have for one of my menus which gives the user the opportunity to search for a loan number from a menu:

with(milonic=new menuname("Loan Search")){
style=menuStyle;
aI("text=<FORM METHOD=GET ACTION=/mypage/loan_info.asp target=_blank name=loansearch><table><tr><td><B><FONT COLOR=339966 SIZE=2>Enter Loan # </FONT></B></td></tr><tr><td><input name=loan size=11></td></tr><tr><td><input type=submit value=Search></td></tr></table></form>;type=form;align=center");
}


What I want to do is be able to open the new page in a new browser session as a dialog style (similar to annoying popup adds). Here is the code I use to do this:

<A HREF="javascript:void(0)" onclick="javascript:window.open('http://www.mypage.com','newWindow', 'width=400, height=400, resizable');">click me</a>

How can I take this second piece of code and implement it into the menu code I already have so that when a search is done through my menu it opens up this new page in dialog style?

Thanks


Poster: Hergio
Dated: Monday September 15 2003 - 19:46:10 BST

You really dont need a form, just alittle javascript. Now take this with a grain of salt because I am currently at my university and can't test this but if you cant get it to work, I will make it work at home and give you it.

Your menu item should look like follows: (notice the ID field of the input, its important and also, its not a submit button, just a regular button that we assign a onclick event to.
Code:
with(milonic=new menuname("Loan Search")){
style=menuStyle;
aI("text=<B>Enter Loan # </B><BR><input name='loan' id='loan' size=11><input type=button onclick='submitQuery();' value=Search>;align=center");
}


Then in the head of your document, have a javascript function that takes the value in the textbox and sends it to a query page, in a popup.
Code:
<SCRIPT>
function submitQuery()
{
   //this document.all[] works in IE, you may have to find the equivalent for NS
   queryStr = document.all["loan"].value;
    window.open("http://www.mypage.com?q=" + queryStr,"newWindow", "width=400, height=400, resizable");
}
</SCRIPT>

And then in your new pop up page, you need to grab the variable out of the URL using either standard server side language (ASP, PHP, etc) or the equivalent HTTP handlers for it. If you dont know how to do that, do a search on google for parsing a url query string. Once you can grab it out of the URL, you can pass it to whatever search algorithm you have. Hope this works, I threw it together in just a couple minutes. ;)


Poster: careyadkins
Dated: Monday September 15 2003 - 21:21:59 BST

That did it....the code had one ";" out of place and once I removed it it worked perfectly....excellent!! (for being away and just typing the code like that...I give you two thumbs up, I'm impressed with the menu!

Thank you!

(FYI....after submitQuery()...the ";" had to be removed...


Poster: careyadkins
Dated: Monday September 15 2003 - 22:14:17 BST

One more quick thing.....how can I tell the new window to center itself....I've tried putting 'align=center' in different places in the code you provided but have been unsuccessful...

Thanks again!


Poster: Hergio
Dated: Tuesday September 16 2003 - 4:08:43 BST

Aww man, and I thought I was spot on! Ahh well, theres still room for improvement. haha

Ok to center it, use this as your new pop up function....I've tested it and it works perfect in IE6. BTW, this will put the popup in the center of the SCREEN, not the browser. So no matter where the browser is, the popup will be smack dab in the center.
Code:
function centeredPopup(URL,popupHeight, popupWidth)
{
  var screenH = screen.height;
  var screenW = screen.width;
  var fromLeft = parseInt((screenW-popupWidth)/2);
  var fromTop = parseInt((screenH-popupHeight)/2);
  //this document.all[] works in IE, you may have to find the equivalent for NS
  var queryStr = document.all["loan"].value;
  window.open(URL + "?q=" + queryStr,"newWindow", "width="+popupWidth+", height="+popupHeight+",left="+fromLeft+",top="+fromTop+" resizable");
}


ALways glad I can help.


Poster: careyadkins
Dated: Tuesday September 16 2003 - 13:32:27 BST

excellent!!! thanks again!


Poster: Hergio
Dated: Tuesday September 16 2003 - 20:21:30 BST

Whew! I was nervous there for a minute. Thought I was slippin'! Glad to help !