I want to change the inner text of a anchor tag with the selected drop down option text
Here is my code of dropdown list whatever option is selected in this drop down list i want to update that option's text in another anchor tag
<span style="white-space: nowrap;" class="" id="shopperlanguage_fs">
<select class="input" id="shopperlanguage" name="shopperlanguage">
<option value="ja_JP" class="japImg">japanees</option>
<option selected="" value="en" class="engImg">English (International)</option>/* whatever option is selected like this i want to get this text */
</select>
</span>
I want to update anchor tag class="dropdown-open" innerhtml with above mentioned dropdown
list selected text
<div class="top-lang clearfix">
<div class="cat-select">
<a href="#" data-dropdown="#dropdown-2" class="dropdown-open"><img src="/site/images
/lang_05.jpg"> English</a> /* this is the anchor tag which innerhtml i want to change with selected dropdown option text */
</div>
</div>
Suppose if in dropdown list selected option having text japanees then i want to change the anchor tag innerhtml text english to japanees.
this is my code which i tried but its not working
<script type="text/javascript">
var e = document.getElementById("shopperlanguage");
var strUsertext = e.options[e.selectedIndex].text;
var langValue =$(".dropdown-open").text()
langValue.innerHTML= strUsertext;
</script>
I want to change the inner text of a anchor tag with the selected drop down option text
Here is my code of dropdown list whatever option is selected in this drop down list i want to update that option's text in another anchor tag
<span style="white-space: nowrap;" class="" id="shopperlanguage_fs">
<select class="input" id="shopperlanguage" name="shopperlanguage">
<option value="ja_JP" class="japImg">japanees</option>
<option selected="" value="en" class="engImg">English (International)</option>/* whatever option is selected like this i want to get this text */
</select>
</span>
I want to update anchor tag class="dropdown-open" innerhtml with above mentioned dropdown
list selected text
<div class="top-lang clearfix">
<div class="cat-select">
<a href="#" data-dropdown="#dropdown-2" class="dropdown-open"><img src="/site/images
/lang_05.jpg"> English</a> /* this is the anchor tag which innerhtml i want to change with selected dropdown option text */
</div>
</div>
Suppose if in dropdown list selected option having text japanees then i want to change the anchor tag innerhtml text english to japanees.
this is my code which i tried but its not working
<script type="text/javascript">
var e = document.getElementById("shopperlanguage");
var strUsertext = e.options[e.selectedIndex].text;
var langValue =$(".dropdown-open").text()
langValue.innerHTML= strUsertext;
</script>
Share
Improve this question
edited Nov 20, 2014 at 6:33
user2787474
asked Nov 20, 2014 at 6:25
user2787474user2787474
1293 gold badges5 silver badges18 bronze badges
1
- could you do a fiddle? – Anubhav Commented Nov 20, 2014 at 6:28
4 Answers
Reset to default 2Just try this.. :)
<script type="text/javascript" src="https://code.jquery./jquery-2.1.1.min.js"> </script>
<span style="white-space: nowrap;" class="" id="shopperlanguage_fs">
<select class="input" id="shopperlanguage" name="shopperlanguage">
<option value="ja_JP" class="japImg">japanees</option>
<option selected="" value="en" class="engImg">English (International)</option>/* whatever option is selected like this i want to get this text */
</select>
</span>
<div class="top-lang clearfix">
<div class="cat-select">
<a href="#" data-dropdown="#dropdown-2" class="dropdown-open">
<img src="/site/images/lang_05.jpg"> English</a> /* this is the anchor tag which innerhtml i want to change with selected dropdown option text */
</div>
</div>
<script type="text/javascript">
$('#shopperlanguage').change(function(){
$('.dropdown-open').text($(this).find('option:selected').text());
});
</script>
try in javaScript
var e = document.getElementById("shopperlanguage");
var strUsertext = e.options[e.selectedIndex].text;
document.getElementsByClassName("dropdown-open")[0].childNodes[1].nodeValue = strUsertext;
DEMO
use On change Jquery with javascript
$('#shopperlanguage').on('change', function () {
$(".dropdown-open")[0].childNodes[1].nodeValue = this.options[this.selectedIndex].text;
}).change();
DEMO
I added <span class="text"></span>
to your markup so it would be easier to select the target area:
$('#shopperlanguage').on('change', function() {
$('.cat-select a span.text').text( $('option:selected',this).text() );
})
.change();
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<span style="white-space: nowrap;" class="" id="shopperlanguage_fs">
<select class="input" id="shopperlanguage" name="shopperlanguage">
<option value="ja_JP" class="japImg">japanees</option>
<option selected="" value="en" class="engImg">English (International)</option>
</select>
</span>
<div class="top-lang clearfix">
<div class="cat-select">
<a href="#" data-dropdown="#dropdown-2" class="dropdown-open"><img src="/site/images
/lang_05.jpg"> <span class="text">English</span></a>
</div>
</div>
<select name="abc" id="abc" onchange="chng()">
<option value=""></option>
<option value="English">English</option>
<option value="Japanese">Japanese</option>
</select>
<a href="#" id="atag">English</a>
<script>
function chng()
{
var s= document.getElementById('abc').value;
document.getElementById('atag').innerHTML = s;
}
</script>
This is working Demo. Please try it.