Page 1 of 1

trouble accesing select.value from ie6 [solved]

Posted: Wed Feb 22, 2006 12:06 am
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

Posted: Wed Feb 22, 2006 12:17 am
by feyd

Code: Select all

document.forms['form name'].elements['element name'].options[document.forms['form name'].elements['element name'].selectedIndex].value;

Posted: Wed Feb 22, 2006 4:25 am
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!! :?

Posted: Wed Feb 22, 2006 5:50 am
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>

Posted: Wed Feb 22, 2006 5:12 pm
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 :? :?

trouble accesing select.value from ie6 [solved]

Posted: Wed Feb 22, 2006 6:33 pm
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