Kenneth Lazos Kenneth Lazos - 7 months ago 23
HTML Question

get the href value from selected option and change the href of the button

I want to get the href value of the selected option so that i can now go to the link that i selected using the button.

Here's my code

<div class="modal fade" id="soa">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Choose the name of student</h4>

<div class="modal-body">
<div class="col-md-12">
<div class="form-group">
<label class="control-label"><span
class="text-danger"></span> Name of Student</label>
<select name="childNames" class="form-control input-lg" id="childNames" data-size="5">
<option value="" selected disabled></option>
<option value="${pageContext.request.contextPath}/app/billsandpayments/invoice">John Dela Cruz</option>
<option value="${pageContext.request.contextPath}/app/billsandpayments/invoice1">Josh Dela Cruz </option>
<option value="${pageContext.request.contextPath}/app/billsandpayments/invoice2">Jane Dela Cruz</option>
<div class="modal-footer">
<a href=''><button type="button" class="btn btn-info">View</button></a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


Add a id to =>

<a id="link" href=''><button type="button" class="btn btn-info">View</button></a>

This should work :

$(document).ready(function() {

    $("#childNames").on('change', function () {

                var ref = document.getElementById("childNames").value;
                $('#link').attr('href', ref);



jsfiddle example