Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Submitting forms

  • 06-04-2005 10:25AM
    #1
    Closed Accounts Posts: 4,655 ✭✭✭


    Does anyone know of any sites that show forms being submitted, even if the submit element is at the top of the page.

    For example hotmail's inbox or something similiar to the attachment I have included.

    Basically I have a form and depending on which link you click on the left (edit or delete) I need to be able to validate the checkboxes select

    i.e. Ensure that when someone clicks "edit" only one textbox is selected or allow for multiple selections when they press "delete" and also to ensure that atleast one checkbox is selected when clicking on either link

    anyone got any pointers


Comments

  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭Eoin


    OK, quite bored here, so did a similar page using client side JScript for the validation. The checkboxes all have the same name so they can be accessed through an array. Sorry if this is nothing like what you were asking...
    <html>
    	<head>
    		<title>test page</title>
    		<script type="text/JavaScript">
    			function doAction(sAction)
    			{
    				// amount of names on the page - retrieved by your serverside code
    				// zero based array, so subtract 1 from the amount
    				var nNameCount = 3;
    
    				// holder for the amount of checkboxes that are checked
    				var nCheckedAmount = 0;
    
    				// loop through the amount of checkboxes
    				for (i = 0; i <= nNameCount; i++)
    				{
    					// if it is checked then increase the variable by one
    					if (document.frmEoin.chkName[i].checked)
    					{
    						nCheckedAmount ++;
    					}
    				}
    
    				// return a message if no options were selected
    				if (nCheckedAmount == 0)
    				{
    					alert("no options were selected");
    				}
    
    
    				// check the action of the form:
    				// if it is delete, then more than one option must be selected
    				if (sAction == "delete")
    				{
    					if (nCheckedAmount > 0)
    					{
    						alert("names can be deleted");
    					}
    				}
    				else if (sAction == "edit")
    				{
    					if (nCheckedAmount == 1)
    					{
    						alert("name can be edited")
    					}
    					else if (nCheckedAmount > 1)
    					{
    						alert("you selected more than one option");
    					}
    				}
    			}
    		</script>
    	</head>
    	<body>
    		<form name="frmEoin" action="thisPage.asp" method="post">
    			<a href="JavaScript: doAction('edit')">edit</a>
    			| <a href="JavaScript: doAction('delete')">delete</a>
    			<table>
    				<tr>
    					<td>Name 1</td>
    					<td><input type="checkbox" value="Name1" name="chkName"></td>
    				</tr>
    				<tr>
    					<td>Name 2</td>
    					<td><input type="checkbox" value="Name2" name="chkName"></td>
    				</tr>
    				<tr>
    					<td>Name 3</td>
    					<td><input type="checkbox" value="Name3" name="chkName"></td>
    				</tr>
    				<tr>
    					<td>Name 4</td>
    					<td><input type="checkbox" value="Name4" name="chkName"></td>
    				</tr>
    			</table>
    		</form>
    	</body>
    </html>
    


Advertisement