Reputation: 133
I have a select input on my page. When I print the page all the options of select get printed instead of the one that is selected. How do I make it so that only the option selected is printed?
<select class="form-control" id=myID onchange="update_status(this)">
<option value="1" selected>Pending</option>
<option value="2">Under-Preparation</option>
<option value="3">Delivered</option>
</select>
Upvotes: 0
Views: 1639
Reputation: 13651
Print the selected choice's value like following snippet. Run code snippet for demonstration.
function update_status(selected_option){
console.log(selected_option.value);
}
<select class="form-control" id=myID onchange="update_status(this)">
<option value="s1" selected>Pending</option>
<option value="s2">Under-Preparation</option>
<option value="s3">Delivered</option>
</select>
Upvotes: 1
Reputation: 1821
Add a this.value instead this, checkout the snippet.
function update_status(vm) {
console.log(vm);
}
<select class="form-control" id=myID onchange="update_status(this.value)">
<option value="1" selected>Pending</option>
<option value="2">Under-Preparation</option>
<option value="3">Delivered</option>
</select>
Upvotes: 0
Reputation: 247
This can be done as below-
function update_status(currentObj){
console.log(currentObj.options[currentObj.selectedIndex].value);
}
Thanks !!
Upvotes: 0
Reputation: 168
It works fine...
javascript print() funtion just shows the rendered[visible] items in pdf preview.
Here is example you can visualize.
This might helps. Have fun.
Upvotes: 0