Solved

PHP Form Var Submit Problem

Posted on 2003-10-30
5
297 Views
Last Modified: 2008-03-17
I have two dropdown lists named:

frm_cbo_top
frm_cbo_bottom

I have an OnChange="submit_form();" in each of these dropdown lists - javascript does a form.submit() call.

The problem is that the "post" method .php file *always* catches this line:

if ($frm_cbo_top)
   {
   // take some action
   }

Even when I make a selection in the bottom dropdown the $frm_cbo_top var if statement gets caught because the code flow goes into that section - I want the $frm_cbo_bottom to catch is I select that dropdown and the $frm_cbo_top  to catch if I select that dropdown - what am I missing here?

Thanks...
0
Comment
Question by:rfresh
[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
5 Comments
 
LVL 2

Expert Comment

by:scully00000
ID: 9650870
Rfresh

Likelihood is that when you submit your form, the top combo box is ubmitting a value (default or otherwise). CAn you post the HTML and the PHP up so I can have a look?

Cheers
0
 
LVL 11

Accepted Solution

by:
shmert earned 125 total points
ID: 9651453
When the form is submitted there's no way to tell which drop-down menu did the submitting.  A workaround would be to add a hidden input to your form, and have the javascript event set that to the appropriate menu.

<input type="hidden" name="which_menu" value="" />
<select name="frm_cbo_top" onchange="this.form.which_menu='frm_cbo_top'; this.form.submit();">

----

Or, you could have 2 hidden fields, each of which contains the original value of the 2 select lists.  THen in the post .php page, compare the values from the hidden inputs with the values from the submitted select lists to see which one changed.  This is a little more code to implement, but doesn't require javascript.
0
 
LVL 4

Expert Comment

by:lokeshv
ID: 9651490
can you please post complete form (HTML with PHP code )..

?

Lk
0
 

Author Comment

by:rfresh
ID: 9651803
I like this solution the best - it seems to be the cleanest and easiest to understand:

<input type="hidden" name="which_menu" value="" />
<select name="frm_cbo_top" onchange="this.form.which_menu='frm_cbo_top'; this.form.submit();">

however, it doesn't work - when I make a selection in the dropdown list (cbo object) I get a javascript error symbol in the lower left corner of my IE 6.0 browser - is there some kind of syntax error?
0
 
LVL 11

Expert Comment

by:shmert
ID: 9661541
Ah, I see a bug in my code, use this.form.which_menu.value='frm_cbo_top';
I was missing the 'value' part (I always forget that :-P)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

730 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