Solved

How can I tell which form field triggered onchange submit for

Posted on 2008-10-30
5
243 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

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

860 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