0

I need your help. I'm trying to insert some text into a textarea-element when the url contains 'number' and an option with value='option2' of a selectbox is selected.

 var contentToInsert = 'Text'; if (location.href.indexOf("/number")) { if (value of selectbox == 'option2') { $("textarea").append(contentToInsert); } } 

How do I check when the option is selected? The text to insert shouldn't be shown when another option is selected. So this would mean that I need on event-handler like onchange.

Have you got an idea?

2 Answers 2

1

jQuery .change() event exists :

Description: Bind an event handler to the "change" JavaScript event, or trigger that event on an element.

Thy with something like that :

http://jsfiddle.net/J4Rkt/

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

Comments

0

Are you sure this line of your code is right?

$("textarea").append(contentToInsert); 

If you are referring to a tag with the id "textarea" then maybe it should be:

$("#textarea").append(contentToInsert); 

Not to mention this will append to that id tag a child node.

Hope it helps :) Cheers!

3 Comments

Hi, well. I can use both. The id and the element. Thank you for the note.
Ah ... I see you're using the tag itself. Hm ... does it work already?
It works but all the textarea will be filled with the value of contentToInsert.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.