Solved

How can I tell which form field triggered onchange submit for

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

920 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

13 Experts available now in Live!

Get 1:1 Help Now