Try this:
<script>
$('#cds').change(function() {
var selectVal = $(this).val();
$("a#linkToChange").attr("href", selectVal);
});
</script>
or
<script>
$('#cds').change(function() {
$("a#linkToChange").attr("href", $(this).val(););
});
</script>
If you want to create the link, try this:
<script>
$('#cds').change(function() {
var selectVal = $(this).val();
$("div#demoDiv").append("<a href='" + selectVal + "'>Result Link</a>");
});
</script>
or
<script>
$('#cds').change(function() {
$("div#demoDiv").append("<a href='" + $(this).val() + "'>Result Link</a>");
});
</script>
If you want to manipulate the existing link, try the following:
<script>
$('#cds').change(function() {
var selectVal = $(this).val();
var url = $("a#linkToChange").attr("href");
url += "/" + selectVal + "/"; // you can replace the slashes with whatever you want to prepend/append to the selected value
$("a#linkToChange").attr("href", url);
});
</script>
NOTE: As stated in the comments, leave the a
and the div
out of the selectors, in front of the #
, as they are redundant. I included them only so that you could see that they are <a>
and <div>
elements.