javascript - radio buttons and passing values -


if(document.getelementbyid('3w').checked) {    alert('3w');  }else if(document.getelementbyid('6w').checked) {    alert('6w');  }
<input type="radio" name="pnltype" id="3w" value="3w" /> 3w  <input type="radio" name="pnltype" id="6w" value="6w" checked />  6w

my problem: run in firefox. example, if tick 3w , choose "reload", alert '3w' not in chrome. in chrome although check 3w, , manually "reload" page, 'the alert '6w'. reason?

in previous versions used onclick option in radio buttons , function: function radioclick() { window.location.reload(); } , again - in firefox behave expected, not in chrome

thanks help.

remove checked attribute in second input.

i feel using jquery easy kind of things. give try http://code.jquery.com/jquery-1.11.1.min.js

<input type="radio" class="any-name" name="pnltype" id="3w" value="3w" /> 3w <input type="radio" class="any-name" name="pnltype" id="6w" value="6w"/>  6w  $('.any-name').on('click', function(){     alert($(this).val()); }); 

http://jsfiddle.net/yasithao3/j1ujhetd/1/


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -