Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to determine which button is clicked on form

Status
Not open for further replies.

excession

Programmer
Sep 22, 2004
111
GB
Hi I have a form in which there is a table, each line of the table displays the detail of a part. the last column of the table has a submit button labeled 'edit'.

The form calls a php script. How can I tell which of the edit buttons was clicked? They all have an identical value unfortunately (since they all display the same text).

Thanks in advance
 
1. have a unique id per button.
2. in each buttons onlcick event pass the id to a hidden field.
3. read the hidden field in PHP.

Known is handfull, Unknown is worldfull
 
Ok, thanks. Only thing I'm not sure about is how to pass the id to the hidden field... how do I go about doing this?

I have a hidden field called 'editme'
Code:
<input type="hidden" name = "editme" value="0">

and the code for the submit button generation is:

Code:
<input type="submit" value="Edit" onClick='document.forms["editform"].elements["editme"].value='ZCYC100.008'>
the value is unique for each button (generated by the script). But when I pick up the value of 'editme' it is always zero.

 
>>'document.forms["editform"].elements["editme"].value='ZCYC100.008'

u are using ' inside '

use this:
'document.forms["editform"].elements["editme"].value="ZCYC100.008"'


Known is handfull, Unknown is worldfull
 
Ah, simple as that.
Thanks a million. I guessed it was something simple but for the life of me just couldn't work out what.
[smile]
 
no problem...

Known is handfull, Unknown is worldfull
 
Here is a another method to do what you requested without resorting to Javascript.

This example should get you going.
Code:
<?
if (isset($_POST['submit'])) {
	foreach ($_POST['submit'] as $k=>$dmy)
		switch ($k) {
			case 'one':
			case 'two':
				echo 'Button <span style="font-weight:bold;color:red">'.$k.'</span>';
				break;
			case 'three':
				echo 'Button <span style="font-weight:bold;color:white;background-color:red">' . $k . '</span>';
				break;
		}
	echo ' was pushed';
}			
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
	<title></title>
</head>
<body>
<form method="post" action="<? echo $_SERVER['PHP_SELF'] ?>">
<input type="submit" name="submit[one]" value="Submit"><br>
<input type="submit" name="submit[two]" value="Submit"><br>
<input type="submit" name="submit[three]" value="Submit">
</form>
</body>
</html>

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top