?
Solved

PHP Form Var Submit Problem

Posted on 2003-10-30
5
Medium Priority
?
301 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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.
Suggested Courses

752 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