StirCrazy Posted July 5, 2006 Share Posted July 5, 2006 Wonder if anyone can help me.I have a page where members can vote using one of serveral radio inputs.The name="vote_id" with value= 1 to 10Can anyone help with a simple onclick="xxxxxx();" that if the user fails to choose an option you get an alert saying "Place your vote" and stays on the same page else carry on with the <form>Does that make any sense? Always be bad at explaining.Thanks in advance.S.C> Quote Link to comment https://forums.phpfreaks.com/topic/13697-onclick-help/ Share on other sites More sharing options...
Cas Posted July 9, 2006 Share Posted July 9, 2006 Something like this? [code]<script language="javascript">function doStuff(){ var radioLength = document.f1.r1.length; var bSet = false; for(var i = 0; i < radioLength; i++) { if(document.f1.r1[i].checked) { bSet=true; break; } } if (!bSet) alert("You need to vote"); else document.f1.submit;}</script><form name="f1"> <input type="radio" id="r1" name="r1" value="1">1</input> <input type="radio" id="r1" name="r1" value="2">2</input> <input type="radio" id="r1" name="r1" value="3">3</input> <input type="button" onclick="doStuff()" value="vote now"/></form>[/code]OR[code]<script language="javascript">function doStuff2(){ document.f2.b1.removeAttribute("disabled"); document.f2.b1.setAttribute("enabled","1"); }</script><form name="f2"> <input type="radio" id="r1" name="r1" value="1" onclick="doStuff2()">1</input> <input type="radio" id="r1" name="r1" value="2" onclick="doStuff2()">2</input> <input type="radio" id="r1" name="r1" value="3" onclick="doStuff2()">3</input> <input type="submit" name="b1" disabled="1" value="vote now"/></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13697-onclick-help/#findComment-55068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.