IE selectedIndex problem

J

Johan Daine

Hi everyone,
I have a main page (search engine) that pops up a window in wich the
user can select a keyword in a select box (up to 4 keywords)
The on change attribute of the select tag calls the following function:


function addKeyword()
{
theindex = document.f2.init.options.selectedIndex;
item = document.f2.init.options[theindex].value;
// alert(theindex + ': ' + item);
if(item=='')
{
return;
}
cnt = window.opener.document.f1.kwd.value;
kword = 'window.opener.document.f1.mot_cle_'+ cnt + '.value=\'' + item +
'\'';
eval(kword);
window.opener.document.f1.mot_cle_1=item;
cnt = (cnt% 4) +1;
// alert('cnt= " + cnt);
window.opener.document.f1.kwd.value = cnt ;
//alert(window.opener.document.f1.kwd.value);
}
// kwd is a hidden field in the main page
// f2 is the popup form
// f1 is the main page form


The problem is that although this code works on
Opera 7.2*, Mozilla 1.0.0 (linux)
and Mozilla (?.?) on Win98
I am not able to get a reasonable value for 'item' in the instruction
item = document.f2.init.options[theindex].value;
in IE6.0
Has someone already got this problem... has found some clue?


Thanks
Johan Daine
 
@

@SM

Johan Daine a ecrit :
Hi everyone,
I have a main page (search engine) that pops up a window in wich the
user can select a keyword in a select box (up to 4 keywords)
The on change attribute of the select tag calls the following function:

var item, cnt, kword;
function addKeyword()

this function is declared in page opened in the popup ?
item, cnt, kword are declared as global variables ? that could help...
{
theindex = document.f2.init.options.selectedIndex;

1) f2 et f1 sont bien des noms ? et non pas des ids ?
forms are named with 'f1' & 'f2' ? or are they id ?

2) and with :
theindex = document.forms['f2']['init'].options.selectedIndex;
or
theindex = document.forms['f2'].elements['init'].options.selectedIndex;
or (après tout, il n'y a qu'1 form et 1 select , non ?)
item = document.forms[0][0].options.selectedIndex;
what does IE ?
item = document.f2.init.options[theindex].value;

3) et bien sûr :
item = document.forms['f2'].elements['init'].options[theindex].value;

4) si ça ne marche pas employer le code de IE ?
if(document.all) { // to be adapted
item=init.options[options.selectedIndex].value; }
// alert(theindex + ': ' + item);
if(item=='')
{
return;
}
cnt = window.opener.document.f1.kwd.value;

cnt = window.opener.document.forms['f1'].elements['kwd'].value;
kword = 'window.opener.document.f1.mot_cle_'+ cnt + '.value=\'' + item +
'\'';
eval(kword);
window.opener.document.f1.mot_cle_1=item;
cnt = (cnt% 4) +1;
// alert('cnt= " + cnt);
window.opener.document.f1.kwd.value = cnt ;
//alert(window.opener.document.f1.kwd.value);

with(window.opener.document.forms['f1']) {
kword = elements['mot_cle'+cnt].value = item ; }
}
// kwd is a hidden field in the main page
// f2 is the popup form
// f1 is the main page form

I am not able to get a reasonable value for 'item' in the instruction
item = document.f2.init.options[theindex].value;
in IE6.0
Has someone already got this problem... has found some clue?

Use the usual maner ?
<select blabla
onchange=" R = this.options.selectedIndex;
if(R==0) alert('Do an other choice')
else
opener.document.forms['f2']['kword'].value=this.options[R].value;
">


--
**************************************************************
Stéphane MORIAUX : mailto:[email protected]
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
**************************************************************
 
J

Johan Daine

@SM said:
Johan Daine a ecrit :

Hi everyone,
I have a main page (search engine) that pops up a window in wich the
user can select a keyword in a select box (up to 4 keywords)
The on change attribute of the select tag calls the following function:


var item, cnt, kword;

function addKeyword()


this function is declared in page opened in the popup ?
item, cnt, kword are declared as global variables ? that could help...

{
theindex = document.f2.init.options.selectedIndex;


1) f2 et f1 sont bien des noms ? et non pas des ids ?
forms are named with 'f1' & 'f2' ? or are they id ?

2) and with :
theindex = document.forms['f2']['init'].options.selectedIndex;
or
theindex = document.forms['f2'].elements['init'].options.selectedIndex;
or (après tout, il n'y a qu'1 form et 1 select , non ?)
item = document.forms[0][0].options.selectedIndex;
what does IE ?

item = document.f2.init.options[theindex].value;


3) et bien sûr :
item = document.forms['f2'].elements['init'].options[theindex].value;

4) si ça ne marche pas employer le code de IE ?
if(document.all) { // to be adapted
item=init.options[options.selectedIndex].value; }

// alert(theindex + ': ' + item);
if(item=='')
{
return;
}
cnt = window.opener.document.f1.kwd.value;


cnt = window.opener.document.forms['f1'].elements['kwd'].value;

kword = 'window.opener.document.f1.mot_cle_'+ cnt + '.value=\'' + item +
'\'';
eval(kword);
window.opener.document.f1.mot_cle_1=item;
cnt = (cnt% 4) +1;
// alert('cnt= " + cnt);
window.opener.document.f1.kwd.value = cnt ;
//alert(window.opener.document.f1.kwd.value);


with(window.opener.document.forms['f1']) {
kword = elements['mot_cle'+cnt].value = item ; }

}
// kwd is a hidden field in the main page
// f2 is the popup form
// f1 is the main page form

I am not able to get a reasonable value for 'item' in the instruction
item = document.f2.init.options[theindex].value;
in IE6.0
Has someone already got this problem... has found some clue?


Use the usual maner ?
<select blabla
onchange=" R = this.options.selectedIndex;
if(R==0) alert('Do an other choice')
else
opener.document.forms['f2']['kword'].value=this.options[R].value;
">


--
**************************************************************
Stéphane MORIAUX : mailto:[email protected]
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
**************************************************************
Thanks for your advices, I am accessing access the forms or elements
with the forms or elements hashes.
It now works withe IE6 and linux browsers including Konqueror ;)

Johan Daine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top