Jump to content

Javascript checking checkboxes


sanfly

Recommended Posts

Hi, I think I have an easy javascript question here

 

I have a form where people need to select if they have entered a competition in a previous year or not.  For selecting previous years, there is a checkbox displayed with the year next to it.  WHen a checkbox is selected, it should invoke a function, check if any of the boxes are ticked, then display the link accordingly.

 

What I dont know how to do is check in ANY of the checkboxes are checked.  Heres what I have so far

 

<script>
	function checkLogin(){
		var yearChecked = window.document.entryType.prevYear;
		if(yearChecked.checked == true){
			document.getElementById("loginForm").innerHTML = 'You may log in and enter using your previous login details<br><br><a href="loginfail.php">CLICK HERE TO LOG IN AND RE-ENTER</a>';
		}
		else{
			document.getElementById("loginForm").innerHTML = 'OR<br><br><a href="enter.php?page=2">CLICK HERE TO ENTER FOR THE FIRST TIME</a>';
		}
	}
</script>
<form name="entryType">
<table align="center" cellspacing="10">
	<tr align="center">
		<td colspan="2">
			<p class="h3">1. Previous Entries</p>
		</td>
	</tr>
	<tr align="center">
		<td>
			Has your band competed in the WORLD BATTLE OF THE BANDS any of the following years:<br>(please check the appropriate box)<br>
			<br>
		<?	for($i = 2005; $i < $thisYear; $i++){	?>
				     <input type="checkbox" name="prevYear[]" value="0" onclick="checkLogin()"> <?=$i?><br>
		<?	}	?>
		</td>
	</tr>
	<tr align="center">
		<td id="loginForm">OR<br><br><a href="enter.php?page=2">CLICK HERE TO ENTER FOR THE FIRST TIME</a></td>
	</tr>
</table>


</form>

 

Link to comment
https://forums.phpfreaks.com/topic/37816-javascript-checking-checkboxes/
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.