简体   繁体   中英

insert text into textarea when option selected

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM