javascript - Checkboxes with anchors -
i have ton of check-box's linked anchors. when check-box clicked goes anchor in same page. there better way code this? have 50 check-box's function packed if statements.this working code 2 of them:
<input type="checkbox" id="1" value="1" onclick="return send();"/> <input type="checkbox" id="2" value="2" onclick="return send();"/> <script> function send(){ if(document.getelementbyid('1').checked){ window.location='#buy'; return false; } if(document.getelementbyid('2').checked){ window.location='#order'; return false; } //and function goes on , on , on... return true; } </script>
and in page want go has
<a name="buy"></a> <a name="order"></a>
if added hash value of input so:
<input type="checkbox" id="2" value="buy" onclick="return send(this);"/>
you so
<script> function send(input) { if(input.checked) { window.location = input.value; return true; } return true; } </script>
if doesn't work switch out value use id
or custom attribute. whatever suits fancy.
Comments
Post a Comment