Closed Thread Icon

Topic awaiting preservation: Need Help With Onchange... Pages that link to <a href="https://ozoneasylum.com/backlink?for=8633" title="Pages that link to Topic awaiting preservation: Need Help With Onchange..." rel="nofollow" >Topic awaiting preservation: Need Help With Onchange...\

 
Author Thread
snips
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 05-01-2003 22:28

I am using a script that opens a pop-up window for the users to make a selection and then it closes the window and puts their selection into a form field on the parent page. I can get the javascript to work if the user clicks a link to open the window, but I would like the window to open with the onchange in the select field. Here is the code on the parent page, I was hoping someone could tell me how to get the value of the selected drop down item to be passed in the onchange command. (replacing the 'XXXX' 's)

The Function:
<script language="JavaScript">
<!--
function ShowPrice(FormName, FieldName, Media) {
window.open("MediaSizeComparison.cfm?FormName=" + FormName + "&FieldName=" + FieldName + "&Media=" + Media, "CalendarWindow", "width=650,height=450, scrollbars=yes, status=yes");
}
//-->
</script>

My Dropdown Menu:
<SELECT name="Media" id="form" onchange="javascript:ShowPrice('Spec', 'AdSize','XXXX')">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</SELECT>

Thanks in advance.

rickindy
Nervous Wreck (II) Inmate

From: Indianapolis, In USA
Insane since: Jan 2002

posted posted 05-02-2003 14:11

This has worked for me (at least in current browsers:
Change your select tag as shown:
<select name="Media" id="form" onChange="ShowPrice('Spec','AdSize',this)">
Don't put the this in quotes. The this will tell your handler to work with the Media select box

Change your function header as shown:
function ShowPrice(FormName,FieldName,Media,selector)
In the function add the following line:
s = selector.value; // gets the value of whatever it was that was selected
The use s to pass along to the popup window.

As a debugging tool, can add an alert right after it gets the value.
Getting this to work wioth old browsers is a little more complicated, but not much.
HTH




snips
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 05-07-2003 15:26

rickindy,
I am trying to do what you suggested but all I am getting passed is [object], rather than the value of the selected item.

Here is the code I am using...(if you have time, can you tell me what I did wrong?)

// function to load the calendar window.
function ShowPrice(FormName, FieldName, SKMediaID,selector) {
window.open("MediaSizeComparison.cfm?FormName=" + FormName + "&FieldName=" + FieldName + "&SKMediaID=" + SKMediaID, "CalendarWindow", "width=650,height=450, scrollbars=yes, status=yes");
s = selector.value; // gets the value of whatever it was that was selected
}
//-->


<SELECT name="Media#i#" id="form" onchange="javascript:ShowPrice('Spec', 'AdSize#i#',this)">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

Thanks

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-07-2003 21:09

Remove the "javascript:" part. That is only used in very specific circumstances; never inside an onsomething attribute such as onchange or onmouseover or anything like that.

rickindy
Nervous Wreck (II) Inmate

From: Indianapolis, In USA
Insane since: Jan 2002

posted posted 05-08-2003 13:50

I got this snippet at home last night. The only real problem I found was that he had defined the function with four arguments, but was only calling it with three. Hopefully fixing that will solve the problem.
I also sent him a sample file using the technique. I'm sure it will all turn out.


Few problems in life can't be solved by chocolate

[This message has been edited by rickindy (edited 05-08-2003).]

snips
Nervous Wreck (II) Inmate

From:
Insane since: Apr 2003

posted posted 05-09-2003 16:02

Thanks for the help rickindy. The problem WAS in fact that my argument number was different than the number of items I was calling.

« BackwardsOnwards »

Show Forum Drop Down Menu