Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

How can I tell which form field triggered onchange submit for

I have a simple 3 field form that lets me select a particular user by first name, last name, or company.  Each fielld contains:
onchange="this.form.submit();"

How can I determine which field triggered the form submission?
0
CheeserTheAverage
Asked:
CheeserTheAverage
  • 2
  • 2
1 Solution
 
Tomarse111Commented:
What other language, if any, are you using for this? Most (if not all) web languages will be able to capture form fields submitted and you can determined which one it was that did the submission by detecting which field is not blank or does not have a default value selected.

0
 
CheeserTheAverageAuthor Commented:
I am using PHP, but sometimes all form fields will have a value. For example, if a company name is selected, submitting the form will fill in the first and last name related to the company in those form fields.  Then if a user selects a different last name, I need to know that the lastName form field was selected, so that it can be used to fill in the new correct first name and company name.

Does this make sense?
// VALIDATE SEARCH FORM
if (!empty($_GET['company2'])) {
	$clientSelected = $_GET['company2'];
}
elseif (!empty($_GET['firstName'])){
	$clientSelected = $_GET['firstName'];
}
elseif (!empty($_GET['lasttName'])){
	$clientSelected = $_GET['lastName'];
}
 
if (isset($clientSelected)) {
	$_GET['company2']  = $clientSelected;
	$_GET['firstName'] = $clientSelected;
	$_GET['lastName']  = $clientSelected;
}

Open in new window

0
 
ahoffmannCommented:
onchange="this.form.submit(this);"
0
 
CheeserTheAverageAuthor Commented:
No that's not what I as looking for.  My question actually states that I am using that to submit the form.  I need the script to know which field was changed to trigger the form submit.  
0
 
ahoffmannCommented:
<script>
function foo(obj,item){obj.changed=item;obj.submit();}
</script>
...
onchange="foo(this.form,'item1');"
...
onchange="foo(this.form,'item2');"

<!-- assuming that your code example already works -->
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now