Jump to content


Photo

onclick help


  • Please log in to reply
1 reply to this topic

#1 StirCrazy

StirCrazy
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 05 July 2006 - 03:35 AM

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>

#2 Cas

Cas
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 09 July 2006 - 10:41 AM

Something like this?

<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>

OR


<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>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users