javascript - how to can validate when click button user with js, this my code -
html
<p><span>a</span><input type="button" value="verdadero" id="v" onclick="verdad()"></p> <p><span>b</span><input type="button" value="falso" id="f" onclick="verdad()"></p>
javascript
function verdad() { var ver = document.getelementbyid('v'); var fal = document.getelementbyid('f'); if (ver == 'v' || fal == 'f' ) { alert('correcto'); return true; } else { alert('falso'); return false; } }
if understand asking...
html
<p><span>a</span><input type="button" value="verdadero" id="v" onclick="verdad(this)"></p> <p><span>b</span><input type="button" value="falso" id="f" onclick="verdad(this)"></p>
javascript
function verdad(elem) { var ver = document.getelementbyid('v'); var fal = document.getelementbyid('f'); if (ver == elem || fal == elem ) { alert('correcto'); return true; } else { alert('falso'); return false; } }
...however, seems may wanting know if verdadero
or falso
clicked. if case, make more since...
html
<p><span>a</span><input type="button" value="verdadero" id="v" onclick="verdad(true)"></p> <p><span>b</span><input type="button" value="falso" id="f" onclick="verdad(false)"></p>
javascript
function verdad(val) { if (val) { alert('correcto'); return true; } else { alert('falso'); return false; } }
Comments
Post a Comment