Welcome to Discussion Forum, where you can ask questions and receive answers from other members of the community.

javascipt getelementsbyname from dropdown(database) : Opencart

1 like 0 dislike
Cant get value of my dropdown(populate from my database):
 
tpl:
 
<div class="form-group required">
<label>Region/state:</label>
<div class="col-sm-10">
<select name="<?php echo $type; ?>_zone_id" id="input-<?php echo $type; ?>-zone" class="form-control" onchange="setCities2();">
</select>
</div>
</div>
 
<p>testzone:</p><p id = 'input-payment-zone1'></p>
 
<script>
function setCities2() {
document.getElementById("input-payment-zone1").innerHTML = document.getElementsByName("<?php echo $type; ?>_zone_id");
}
</script>
Any advice?
asked May 3, 2017 in Opencart by harsh (8,710 points)

2 Answers

0 like 0 dislike

Hi,

Use " document.getElementsByName("<?php echo $type; ?>_zone_id").value;" instead.

We have Highlighted it in the code. It is shown below:

<script>
function setCities2() {
document.getElementById("input-payment-zone1").innerHTML = document.getElementsByName("<?php echo $type; ?>_zone_id").value;
}
</script>
I hope it helps. Please let us know if your problem is resolved.
 
Thank you.
answered May 30, 2017 by teo.arjun (2,610 points)
0 like 0 dislike

Try this:

<script>
window.onload = function() {
    var name='<?php echo $type; ?>'+'_zone_id';
    var setCities2 = function () {
        document.getElementById("input-payment-zone1").innerHTML = document.getElementsByName(name);
    }
}
</script>

 

answered May 31, 2017 by nimish (200 points)

Related questions

1 like 0 dislike
1 answer 672 views
1 like 0 dislike
1 answer 323 views
323 views asked Mar 2, 2017 in Opencart by harsh (8,710 points)
0 like 0 dislike
0 answers 46 views
46 views asked Mar 2, 2017 in Opencart by harsh (8,710 points)
0 like 0 dislike
0 answers 468 views
468 views asked Mar 1, 2017 in Opencart by harsh (8,710 points)
0 like 0 dislike
0 answers 58 views
58 views asked Mar 1, 2017 in Opencart by harsh (8,710 points)
...