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?
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/
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!
精彩评论