PDA

View Full Version : simple answer needed


jkhalbe
10-15-2004, 04:58 PM
Ok, I am a complete dummy when it comes to this stuff...If anyone could just answer this question for me that would be great. You can also laugh at me all you want for i am a straight up newbie at this stuff. I have a generic script for playing midi files on my website. My only problem is that i need these links to open up in a new window. Can you help me debug in order to do so. Using html, i would use _blank command, but what do i use for this script. Thanx, your help is appreciated for this newbie here.

~Jeff

Below is script.

<form name="form">
<div align="center">
<select name="site" size=1 onChange="javascript:formHandler()">
<option value="">Listen to Music Here While you Browse...
<option value="http://www.jeffhalbe.com/joker.mid">Steve Miller Band - Joker</option>
<option value="http://www.jeffhalbe.com/wonder_wall.mid">Oasis - Wonderwall</option>
<option value="http://www.jeffhalbe.com/slowride.mid">Beastie Boys - Slowride</option>
<option value="http://www.jeffhalbe.com/run_around.mid">Blues Travellers - Run Around</option>
<option value="http://www.jeffhalbe.com/november_rain.mid">Guns N Roses - November Rain</option>
<option value="http://www.jeffhalbe.com/hotel_california.mid">Eagles - Hotel California</option>
<option value="http://www.jeffhalbe.com/everybody.mid">Backstreet Boys - Everybody</option>
<option value="http://www.jeffhalbe.com/abracadabra.mid">Steve Miller Band - Abracadabra</option>
<option value="http://www.jeffhalbe.com/red_wine.mid">UB40 - Red Wine</option>
<option value="http://www.jeffhalbe.com/cantloveyou.mid">UB40 - Can't help falling</option>
<option value="http://www.jeffhalbe.com/one.mid">Metallica - One</option>
<option value="http://www.jeffhalbe.com/no_woman_no_cry.mid">Bob Marley - No Woman No Cry</option>
<option value="http://www.jeffhalbe.com/maryjane.mid">Tom Petty - Mary Jane's Last Dance</option>
<option value="http://www.jeffhalbe.com/learning_to_fly.mid">Tom Petty - Learning To Fly</option>
<option value="http://www.jeffhalbe.com/dust_in_the_wind.mid">Kansas - Dust in the Wind</option>
<option value="http://www.jeffhalbe.com/purple_haze.mid">Jimi Hendrix - Purple Haze</option>
<option value="http://www.jeffhalbe.com/knockin.mid">Guns N Roses - Knocking on Heavens Door</option>
<option value="http://www.jeffhalbe.com/barbie_girl.mid">Aqua - Barbie Girl (Funny)</option>
<option value="http://www.jeffhalbe.com/california_love.mid">Tupac - California Love</option>
</select>
</div>
</form>

Roy Sinclair
10-15-2004, 05:17 PM
We need to see the script, you posted the form which calls the script but not the script.

jkhalbe
10-15-2004, 05:21 PM
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}
// End -->
</SCRIPT>

jbot
10-15-2004, 05:27 PM
try this:


<form name="form">
<div align="center">
<select name="site" size=1 onChange="javascript:formHandler(this)">
<option value="">Listen to Music Here While you Browse...
<option value="http://www.jeffhalbe.com/joker.mid">Steve Miller Band - Joker</option>
<option value="http://www.jeffhalbe.com/wonder_wall.mid">Oasis - Wonderwall</option>
<option value="http://www.jeffhalbe.com/slowride.mid">Beastie Boys - Slowride</option>
<option value="http://www.jeffhalbe.com/run_around.mid">Blues Travellers - Run Around</option>
<option value="http://www.jeffhalbe.com/november_rain.mid">Guns N Roses - November Rain</option>
<option value="http://www.jeffhalbe.com/hotel_california.mid">Eagles - Hotel California</option>
<option value="http://www.jeffhalbe.com/everybody.mid">Backstreet Boys - Everybody</option>
<option value="http://www.jeffhalbe.com/abracadabra.mid">Steve Miller Band - Abracadabra</option>
<option value="http://www.jeffhalbe.com/red_wine.mid">UB40 - Red Wine</option>
<option value="http://www.jeffhalbe.com/cantloveyou.mid">UB40 - Can't help falling</option>
<option value="http://www.jeffhalbe.com/one.mid">Metallica - One</option>
<option value="http://www.jeffhalbe.com/no_woman_no_cry.mid">Bob Marley - No Woman No Cry</option>
<option value="http://www.jeffhalbe.com/maryjane.mid">Tom Petty - Mary Jane's Last Dance</option>
<option value="http://www.jeffhalbe.com/learning_to_fly.mid">Tom Petty - Learning To Fly</option>
<option value="http://www.jeffhalbe.com/dust_in_the_wind.mid">Kansas - Dust in the Wind</option>
<option value="http://www.jeffhalbe.com/purple_haze.mid">Jimi Hendrix - Purple Haze</option>
<option value="http://www.jeffhalbe.com/knockin.mid">Guns N Roses - Knocking on Heavens Door</option>
<option value="http://www.jeffhalbe.com/barbie_girl.mid">Aqua - Barbie Girl (Funny)</option>
<option value="http://www.jeffhalbe.com/california_love.mid">Tupac - California Love</option>
</select>
</div>
</form>


<script type="text/javascript">
<!-- Begin
function formHandler(field)
{
location.href = field.options[field.selectedIndex].value;
}
// End -->
</script>

jkhalbe
10-15-2004, 05:37 PM
i tried it, it still opens up in the same window....

Utterly confused??

jbot
10-15-2004, 07:12 PM
i tried it, it still opens up in the same window

sorry, didn't read your whole post.

add this to the form tag: target="_blank"

so, it will be <form name="form" target="_blank">

then, use this for the script:

<script type="text/javascript">
<!-- Begin
function formHandler(field)
{
field.form.action = field.options[field.selectedIndex].value;
}
// End -->
</script>

ok :D

Roy Sinclair
10-15-2004, 07:54 PM
The following changes to your code will do the trick (changes are highliighted):


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var popupWindow;
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
popupWindow = window.open(URL,'APopup')
}
// End -->
</SCRIPT>


Er, Jbot -- you seem to be going down the wrong path here, this form isn't being submitted.

jkhalbe
10-15-2004, 08:23 PM
Roy, the code you gave me works wonders. It does exactly what i wanted it to do. Now there is one more thing i ask (if its even possible to do).

Is there anything i can add to the script that makes it open up in a new window (which you already did for me), but then makes it minimize or open as a real small window that way the original page is still being viewed without having to minimize anything. Thanks for your help.

Even if nothing else can be done, it still does what i want it to. Thanks again,


~Jeff

jkhalbe
10-15-2004, 08:29 PM
Oh i just realized something. You guys can check it out for yourself. If you go to www.jeffhalbe.com/test.htm and look for yourself you may encounter something i did.

If you click the drop down box to play a song, it will open in a new window and load.

Try this though and tell me if it does this for you. If you minimize it while the song is still playing, then go back to the drop down box and choose another song, the current song will stop playing but the newly loaded song wont play until you maximize the song window. Weird. Thats why i ask if it can open up in a new window at a set dimension or if there is anything else that can be done to fix this.

Thanx again and check it out for yourself if you'd like.

www.jeffhalbe.com/test.htm

jkhalbe
10-15-2004, 08:32 PM
did i mention i use quicktime player 6.5.1 and you might use something else. let me know if you see any obvious discrepancies.

jbot
10-15-2004, 08:51 PM
Er, Jbot -- you seem to be going down the wrong path here, this form isn't being submitted.

i know i just wanted to show an alternative method. poviding that there are no other fields in the form, this would make a pretty accessible method - add a submit button and off you go. :cool:

of course, i inadvertently ommitted a line in the script block. it should read:

<script type="text/javascript">
<!-- Begin
function formHandler(field)
{
field.form.action = field.options[field.selectedIndex].value;
field.form.submit();
}
// End -->
</script>


if you use a button, you won't need to use onclick to call the above function.

Is there anything i can add to the script that makes it open up in a new window (which you already did for me), but then makes it minimize or open as a real small window that way the original page is still being viewed without having to minimize anything. Thanks for your help.

that won't work in IE as of XP/SP2 (not that you should do that anyway).

Roy Sinclair
10-15-2004, 09:27 PM
http://polymer.bu.edu/~ccruz/javascript/reference.html

Scroll down to the "window.open" reference and you'll see what you can control. Note that you can only shrink a window to a certain size, the browser will refuse to go smaller.

jkhalbe
10-15-2004, 10:30 PM
Man that is a great reference source. You really helped me Roy. Thats why i cam to this forum. These are so helpful. Ultimately, i am making a personal site for my college friends to go to and laugh. The point of this is for my learning experience. I have never done anything with code before 3 weeks ago. I am reading, implementing and more. You were a great help.

As its obvious to the script, its a popup, and popup blockers prevent it from loading. Oh well, notation solves that problem. Also though, if i minimize it and go to load a new song it wont start playing unless i bring that window up. But if i leave the window up and in the back it will load automatically.

It's kinda weird. Im not worried about it. Thanks a lot and feel free to check out the site. www.jeffhalbe.com

~Jeff

jamescover
10-16-2004, 02:08 AM
...thanks, Jbot. :D