Solved

How can I tell which form field triggered onchange submit for

Posted on 2008-10-30
5
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to count occurrences of each item in an array.
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…

726 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