Re: Reloading a page when selection made in select box
by "Derek Lavine" <derek(at)realware.com.au>
|
Date: |
Tue, 20 Jun 2000 16:20:48 +1000 |
To: |
"Cyanide _7" <leo7278(at)hotmail.com> |
Cc: |
<hwg-languages(at)hwg.org> |
References: |
hotmail |
|
todo: View
Thread,
Original
|
|
Thanks very much for that Cyanide_7 and the explanation
Derek
----- Original Message -----
From: Cyanide _7 <leo7278(at)hotmail.com>
To: <derek(at)realware.com.au>
Cc: <hwg-languages(at)hwg.org>
Sent: Tuesday, June 20, 2000 4:19 PM
Subject: Re: Reloading a page when selection made in select box
> this solution was just posted to a similar question. here is the
> explanation behind it:
>
> the standard way to retrieve the value of the currently selected option
> in a select object is to reference the option in its array with the select
> object's selectedIndex property, then read that option's value. IE made a
> shortcut that only works in IE by giving the select object a value
property
> that reflects the currently selected options value.
>
> also, you should assign the string to the href property of the location
> object, not the object itself. this is another example of a browser
letting
> ppl get away with sloppy code. in any case, here is the safer code:
>
> function companyChanged(field) {
> var cid = field.options[field.selectedIndex].value;
> location.href = "/customer/customer_add.cfm?f_companyId="+cid;
> }
>
> - Cyanide_7
>
> >
> >Ooops I thought I sent this the other day.
> >
> >Thanks Romek for that idea, unfortunately the values and the indexes do
not
> >match in all cases where I use this. Has any one any other ideas.
> >
> >Thanks
> >
> >Derek
> >
> >----- Original Message -----
> >From: Romek aka webadmin <www(at)wipos.p.lodz.pl>
> >To: Derek Lavine <derek(at)realware.com.au>
> >Cc: <hwg-languages(at)hwg.org>
> >Sent: Saturday, June 17, 2000 3:01 AM
> >Subject: Re: Reloading a page when selection made in select box
> >
> >
> > > At 08:42 16-06-00 +1000, you wrote:
> > > >Hi,
> > > >
> > > >I have a java script function
> > > >
> > > >function companyChanged(field) {
> > > > window.location='/customer/customer_add.cfm?f_companyId=' +
> >field.value;
> > > >}
> > > >
> > > >
> > > >And in the HTML I have a select widget
> > > >
> > > ><select name="f_companyId" size=1 onChange="companyChanged(this)">
> > > ><option value="0">None
> > > ><option value="1">Abc
> > > ><option value="2">Xyz
> > >
> > >
> > > >In netscape the field.value always comes to be null and not the
number
> > > >associated with the selection made.
> > > >
> > > >Yet if I change companyChanged(field) to look like this
> > > >
> > > >function companyChanged(field) {
> > > > alert(field)
> > > >}
> > > >
> > > >Netscape correctly identifies field as being the select object.
> > > >Has anyone any ideas.
> > >
> > > Try to use selectedIndex property of the field:
> > >
> > > function companyChanged(field)
> > > {
> > > window.location=
> > > '/customer/customer_add.cfm?f_companyId=' + field.selectedIndex;
> > > }
> > >
> > > if you keep numeric values as 0, 1, 2 then selectedIndex
> > > has the same values and the script works (tested in Opera
> > > which is close to NN 3 as far as JavaScript is concerned).
> > >
> > > >Thanks in advance
> > > >
> > > >Derek
> > >
> > >
> > > --
> > > Romek Zylla
> > > ~~~~~~~~~~~ after all the work done by Micro$oft (R) ~~~~~~~~~~
> > > Personal Computer Science is an experimental one (C)
> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >
> >
>
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA