Solved

How can I tell which form field triggered onchange submit for

Posted on 2008-10-30
5
242 Views
Last Modified: 2012-05-05
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
Comment
Question by:CheeserTheAverage
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Tomarse111
ID: 22843893
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
 

Author Comment

by:CheeserTheAverage
ID: 22844108
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22844295
onchange="this.form.submit(this);"
0
 

Author Comment

by:CheeserTheAverage
ID: 22844345
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
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 22844401
<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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question