0

I have problem with the onclick event in Chrome it's working in FireFox.

my code is:

<select type="list" name="adscity"  id="adscity" class="ads-select2" >
<?php while($row=mysql_fetch_array($result)) { ?>
    <option value="<?php echo $row['id']; ?>" onclick="document.getElementById('adscity_h').value=this.value" >
    <?php echo $row['title']; ?> </option>
<?php } ?>
</select>
Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
saber
  • 336
  • 5
  • 15
  • Your code contains unopened tags and braces, could you try copying a cleaner and readable version please? – gpgekko Jan 28 '14 at 13:27
  • I see no unopened tags or unopened braces but take a look at [this](http://stackoverflow.com/questions/9972280/onclick-on-option-tag-not-working-on-ie-and-chrome) – elitechief21 Jan 28 '14 at 13:34
  • well, of course the `onclick` event works on chrome, but you need the `onchange` event... don't blame the tools, if the only tool is... well... you know what I mean – Elias Van Ootegem Jan 28 '14 at 14:04
  • possible duplicate of [onclick="location.href='link.html'" does not load page in Safari](http://stackoverflow.com/questions/6418634/onclick-location-href-link-html-does-not-load-page-in-safari) – Paul Sweatte Jan 28 '14 at 16:43

2 Answers2

1

Try this please. you should add 'onChange' event in <select> tag instead on onClick in <option>

<select onchange="document.getElementById('adscity_h').value=this.value">
Maz I
  • 3,664
  • 2
  • 23
  • 38
0

I assume that your option tags are in a select tag.

The jquery code:

$('#adscity').on('change', function(){
   $('#adscity_h').val($(this).val());
})
HarryFink
  • 1,010
  • 1
  • 6
  • 6