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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.