Solved

PHP Form Var Submit Problem

Posted on 2003-10-30
5
293 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
Comment Utility
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
Comment Utility
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
Comment Utility
can you please post complete form (HTML with PHP code )..

?

Lk
0
 

Author Comment

by:rfresh
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

744 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