Simple variable/string question

C

charliefortune

I have three drop down menus that when changed call a simple js
function, passing a value i.e.

<SELECT name="Team" onChange="change('national');">

the function defined at the beginning is

function change(which) {
current = document.premForm.Team.selectedIndex;
document.images.premShirt.src = "assets/shirts/"
+document.premForm.Team[current].value + ".gif";
}

the var 'which' is being passed succesfully, but i can't work out how
to change

document.premForm.Team.selectedIndex;

into

document.whichForm.Team.selectedIndex;

depending on what value the function receives. My 3 forms are called
premForm,nationalForm and worldForm
 
R

RobG

charliefortune said on 04/04/2006 8:57 AM AEST:
I have three drop down menus that when changed call a simple js
function, passing a value i.e.

<SELECT name="Team" onChange="change('national');">

the function defined at the beginning is

function change(which) {
current = document.premForm.Team.selectedIndex;

pass a reference to the select to the function:

<SELECT name="Team" onChange="change(this, 'national');">

now the your function is:

function change(selectEl, which)
{
current = selectEl.selectedIndex;

document.images.premShirt.src = "assets/shirts/"
+ document.premForm.Team[current].value + ".gif";
}

the var 'which' is being passed succesfully, but i can't work out how
to change

document.premForm.Team.selectedIndex;

into

document.whichForm.Team.selectedIndex;

Presuming the name of the form is 'nationalForm', then:


document.forms[which + 'Form'].Team.selectedIndex;


Read the FAQ section on accessing properties:
 
C

charliefortune

Thank you, I have it working now, but without the parameter you added
to my function, the selectE1. I didn't quite get that bit, but I
obviously have some reading to so, so thanks again.
 

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
473,794
Messages
2,569,641
Members
45,354
Latest member
OrenKrause

Latest Threads

Top