Select box value getting in another function Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Select box value getting in another function without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am getting select box value like code below:

$(document).on('change','.test',function(){
   var val = $('option:selected',this).val()
   alert(val);
});

How can I get that selected value in below function:

function test_data()
{
   //get select box value here
}

Answer

you could do like below :

var value = $('select.test').val();
alert(value)

or you can use on change event

<select onchange="test(this.value)" ></select>
<script>
function test(value) {
//value is selected option value
}
</script>

jsfiddle

We are here to answer your question about Select box value getting in another function - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji