Level 46
Don't give two elements the same id. Use a class instead.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
<input type="text" id="roleid" />
<input type="text" id="roleid" />
<select name="test" id="test">
<option value="A">One</option>
<option value="B">Two</option>
</select>
$(document).ready(function() {
$('select[name="role"]').on('click', function() {
var optionID = $(this).val();
var textBox = document.getElementById("roleid");
if(stateID) {
textBox.value = optionID;
}
});
});
In above case only one textbox is populating. I want to populate both textbox on same id, because in my program the text box is generating using foreach.
Thanks @topvillas it works for me
$(document).ready(function() {
$('select[name="role"]').on('click', function() {
var stateID = $(this).val();
var textBox = document.getElementsByClassName('abc');
if(stateID) {
for(var i = 0; i < textBox.length; i++){
textBox[i].value=stateID;
}
}
});
});
<input type="text" class="abc" name="roleid" id="roleid">
Please or to participate in this conversation.