running javascript on php page or 2 submit buttons in 1 form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

running javascript on php page or 2 submit buttons in 1 form

Post by deejay »

HI

i have a function in javascript

Code: Select all

function tickAll() {
		document.form1.q1.checked = true;
		document.form1.q2.checked = true;
		document.form1.q3.checked = true;
		
}
and called up with

Code: Select all

<INPUT type="button" name="submit" onClick="javascript:tickAll()" value="Accept All" >
but cant seem to get this to work on a PHP page. According to post i have read there shouldn't really be a problem. I have also tried to make a tick all in php instead but donot undersatnd how to use 2 submits in 1 form.

Any help is appreciated, thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

this one works fine for me

Code: Select all

<html>
	<head>
		<script type="text/javascript">
			function tickAll() {
      	document.form1.q1.checked = true;
      	document.form1.q2.checked = true;
      	document.form1.q3.checked = true;
      	return true;
    	}
    </script>
	</head>
	<body>
		<pre><?php print_r($_POST); ?></pre>
		<hr />
		<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<input type="checkbox" name="q1" id="q1"/><label for="q1">q1</label><br />
			<input type="checkbox" name="q2" id="q2"/><label for="q2">q2</label><br />
			<input type="checkbox" name="q3" id="q3"/><label for="q3">q3</label><br />
			<INPUT type="button" name="submit" onClick="javascript:tickAll()" value="check All" />
			<INPUT type="submit" name="submitAll" onClick="javascript:tickAll()" value="submit all" />
			<input type="submit" />
		</form>
	</body>
</html>
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Post by deejay »

thanks for the reply, i will not have a chance to look at this now until the end of today. Will let you know whether I can get this to work for me then.
Post Reply