Jump to content

onclick help


StirCrazy

Recommended Posts

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 10

Can 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>
Link to comment
https://forums.phpfreaks.com/topic/13697-onclick-help/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/13697-onclick-help/#findComment-55068
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.