1

i have select input having id "slt" i want to pick innertext of value and assign its text to another div. i have a code from which i am getting its value now i want to make a onchange function when user change input value, the value should be assign to another div.

jQuery code:

var ch= $('#sltnew option:selected').html();
$('#catch').html(ch);

HTML:

<div id="catch">select city</div>;

<select name="sltnew" id="slt" onchange="change ()">
    <option value="opt1">hello</option>
    <option value="opt2">Option 2</option>
    <option value="opt3">Option 3</option>
    <option value="opt4">Option 4</option>
    <option value="opt5">Option 5</option>
    <option value="opt6">Option 6</option>
    <option value="opt7">Option 7</option>
    <option value="opt8">Option 8</option>
</select>

3 Answers 3

3

Try this:

// on load
var ch = $('#sltnew option:selected').html();
$('#catch').html(ch);

// on change
$("#slt").change(function() {
    $('#catch').html($(":selected", this).html())
});
Sign up to request clarification or add additional context in comments.

Comments

2

I think you are looking for .change()

http://api.jquery.com/change/

$("#slt").change(function(){

    $('#catch').html($(this).val());

});

Comments

0

this maybe? the .change() method triggers as soon as the content of the "slt" is clicked. then you have to use the "selected" attribute (example in the link) to retrieve the value you need and process it

Comments

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.