Solved

PHP Form Var Submit Problem

Posted on 2003-10-30
5
294 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
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

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

Suggested Solutions

Title # Comments Views Activity
Keep getting 503 on Curl request 6 30
Apache/PHP: Cannot make phpinfo() and phpmyadmin work 4 34
xampp tool 12 25
Checking if varaible is empty 6 30
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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