trouble accesing select.value from ie6 [solved]

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ademus
Forum Newbie
Posts: 10
Joined: Thu Feb 16, 2006 7:00 am

trouble accesing select.value from ie6 [solved]

Post by ademus »

I have a <select> input from which depends another one. I've created a function that onChange of the "parent" <select>, feeds the "child" one with its proper values. The problem is that i cannot acces the value selected in the "parent" <select>.
The function is pretty simple

Code: Select all

function obtenerPcia(){
		if ( document.medio_nuevo.provincia.value == 'Buenos Aires' ){
			return;
		} else {
			window.open("./medioscar.php?provincia='"+document.medio_nuevo.provincia.value+"'");
		}
	}
In mozilla the script runs fine and it shows the correct value, but in ie6 it won't altough i can get the selectedIndex... But the value won't show up, however i try to access it (i've tried with the options[select.selectedIndex].value and the result was the same)
Im pretty desperate so any help is welcome
Thanks! :P
Last edited by ademus on Wed Feb 22, 2006 6:34 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

document.forms['form name'].elements['element name'].options[document.forms['form name'].elements['element name'].selectedIndex].value;
ademus
Forum Newbie
Posts: 10
Joined: Thu Feb 16, 2006 7:00 am

Post by ademus »

no luck with that... is so weird... if i run the script within firefox it works lovely, but when i do it in ie6 it won't show the expected result!! :?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If you gie the <select> an id it's clearer what's going on IMO.

Code: Select all

function showval()
{
    el = document.getElementById('foo');
    alert(el.options[el.selectedIndex].value); //The options are an array, the currently selected one is index by selectedIndex
}

Code: Select all

<select name="foo" id="foo" onchange="showval()">
<option>Test</option>
</select>
ademus
Forum Newbie
Posts: 10
Joined: Thu Feb 16, 2006 7:00 am

Post by ademus »

see it for yourself http://www.santiagojreig.com.ar/docek/medioscar.php

when you open the php with ie6 select some option from Provincia and see that despite the simple sentence of javascript that the browser should run the result is a blank alert window. on the other hand if you open the url with firefox it works fine :? :?
ademus
Forum Newbie
Posts: 10
Joined: Thu Feb 16, 2006 7:00 am

trouble accesing select.value from ie6 [solved]

Post by ademus »

instead of recalling the document with the variables passed as GET values, i worked a bit on javascript and onchange of the "parent" <select> the form sets its action towards itself and reloads with the selected value as a $_POST value

Thanks anyway... :D
Post Reply