Solved

How can I tell which form field triggered onchange submit for

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now