0

I haven't used JavaScript for sometime.

I'm trying to get this following script working so if I select "Ireland" in the dropdown, the Ireland select menu appears below. The same goes for America and Canada.

http://jsfiddle.net/mcgarriers/DPSe4/

However it's just not working. Can anyone take a look and explain why?

I'm sure it's something simple.

Many thanks for any help at all.

3 Answers 3

1

Now its working :

http://jsfiddle.net/DPSe4/3/

You needed to pass the "SELECT" node to the function , instead of the form.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow, that was simple :) Thank you so much for clearing this up. I'd been racking my brain crazy trying to resolve it. Have a great day!!
Will go "green" in 8 minutes time :D
0

It is because of this keyword. Inside of your function it reffers to DOM window object. Use

<select onchange='switchStates(this)'>
....

<script>
    switchStates(Sender){
       alert(Sender.selectedIndex+"-"+Sender.value);
    }
</script>

1 Comment

Many thanks, Jan. I've chosen DhruvPathak's answer this time, but I really appreciate your response here.
0

You're passing this.form to the function, but you've not put the parameter into the function parameter list. i.e.:

function switchStates( form ) {
  ...
}

Also, you're not referencing the form's select object; you need form.dcountry.selectedIndex

1 Comment

Hi Nick. Thank you for taking the time to reply and help me out. I've selected the answer from DhruvPathak above but thanks for your comments and answer too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.