I got option values from a query, and i added into dropdown list. here's the code:
$(document).ready(function() {
$( "#uname" ).focusout(function() {
$("#loader").show();
var uname = $( "#uname" ).val(),
v_request = $.ajax({
url : "data/get_agent.php",
type : "POST",
dataType: "json",
data : {
uname : uname
}
});
v_request.done(function(data, status, jqXHR) {
$("#application").empty();
var option = document.createElement("option"),
select = document.getElementById("application");
option.text = '-- Application --';
option.value = '';
select.appendChild(option);
$.each(data.data, function(key, data) {
var option = document.createElement("option"),
select = document.getElementById("application");
option.text = data.appname;
option.value = data.appvalue;
select.appendChild(option);
if(data.defvalue == 1)
select.value = data.appvalue;
});
});
})
});
the option value contain url link, i want call it in a a href tag. here's code:
<tr>
<td>
<select id="application" name="application">
<option value=""> -- Application -- </option>
</select>
</td>
</tr>
<tr>
<td align="center" style="padding-top:10px;" id="logInBtn">
<a id="link_combo" href="javascript:void(0);" onmouseout="MM_swapImgRestore()"><img src="resources/images/straclick-login.png" name="btn-login" border="0" width="280" id="btn-login" /></a>
</td>
</tr>
i don't know how to insert drop down value into href.
Just adding to Barmar's answer, here's an example: http://jsbin.com/panacoqaje/1/ (I would have commented but I don't yet have 50 reputation :P)
$("#application").change(function () {
console.log(this.value);
$("#link_combo").attr('href', this.value);
$("#link_combo").text($("#application option:selected").text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
<td>
<select id="application">
<option value="http://google.com/">Google</option>
<option value="http://benzhang.xyz/">A Blog</option>
</select>
</td>
</tr>
<tr>
<td align="center" style="padding-top:10px;" id="logInBtn">
A link to:
<a id="link_combo" href="#">Unicorn Land</a>
</td>
</tr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With