Sunday, 15 January 2012

javascript - How to confirm the chosen radio button? -



javascript - How to confirm the chosen radio button? -

i have created 3 radio buttons. want run function onclick inquire user confirm chosen radio button , tell checked radio button value is. if user doesn't confirm checked radio button, radio button deselected. code have written failed.

<input id="a1" type="radio" name="type" value="a1" onclick= "confirmation();" />a1 <input id="a2" type="radio" name="type" value="a2" onclick="confirmation();" />a2 <input id="a3" type="radio" name="type" value="a3" onclick="confirmation();"/>a3

javascript

function confirmation() { if (document.getelementbyid('a1').checked ) { ty = document.getelementbyid('a1').value var ask= confirm("you have chosen " + ty + " type \n if have chosen right type, click ok! " ) } if (document.getelementbyid('a2').checked) { level = document.getelementbyid('a2').value; var ask= confirm("you have chosen " + ty + " exam level \n if have chosen right type, click ok! " ) } if (document.getelementbyid('a3').checked) { ty = document.getelementbyid('r1').value; var ask= confirm("you have chosen " + ty + " type \n if have chosen right type, click ok! " ) } if (ask==true) { alert("you clicked ok"); } if (ask==false) { alert("you clicked cancel"); } }

i think can sum this:

class="snippet-code-js lang-js prettyprint-override">function confirmation(obj) { obj.checked ? confirm("you have chosen " + obj.value + " type \n if have chosen right type, click ok!") ? alert("you clicked ok") : obj.checked = false : ""; } class="snippet-code-html lang-html prettyprint-override"><input id="a1" type="radio" name="type" value="a1" onclick="confirmation(this);" />a1 <input id="a2" type="radio" name="type" value="a2" onclick="confirmation(this);" />a2 <input id="a3" type="radio" name="type" value="a3" onclick="confirmation(this);" />a3

pass this function. this refers dom object.

javascript

No comments:

Post a Comment