473,804 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dependant dropdowns with PHP?

348 Contributor
I got a winner here..

I need a solution that will use a single html select and two input fields that depend on the value selected.

This dropdown will have 3 values. If a certain values is selected, I need two input boxes to appear. If either of the other two values are selected, then no additional input boxes should be added.

This sounds like a job for AJAX i'm sure but I haven't a clue about AJAX.

What I have now is a select tag with a js onchange event that fires when the user selects the value from the select box. With php, I test for the POST var and if it is the value where I need the additional input boxes, I echo them. This is all well and good until I need to submit the page.

In theory, I setup the page using the onchange and then submit the entire page after it has been completed. This is where I have my problem because to do it like this, I would need to nest form tags and I don't think this is correct.

Does someone have a code sample they could share with me or point me in the direction that I need to go?

Thanks,

Frank
Aug 13 '08
18 1566
samatair
61 New Member
To get the selected value of a <select>, you have to use this.options[this.selectedIn dex].value instead of this.value.

Thank you very much for getting me right with "this.optio ns".
But it worked for me. I think your way should be right.
Pls can you let me know the difference between the two.
If only I am not diverting from fjm's question.
Aug 14 '08 #11
acoder
16,027 Recognized Expert Moderator MVP
To get the selected value of a <select>, you have to use this.options[this.selectedIn dex].value instead of this.value.
Hmm, why not this.value?

By the way, I think this thread should be moved to the JavaScript forum.
Aug 14 '08 #12
fjm
348 Contributor
He's talking about line 9 in the code above.
Thanks r035198x for pointing that out. At least I can follow along now.

I really need to pick up a book on javascript.
Aug 14 '08 #13
fjm
348 Contributor
Thank you very much for getting me right with "this.optio ns".
But it worked for me. I think your way should be right.
Pls can you let me know the difference between the two.
If only I am not diverting from fjm's question.
Thanks Samatair for the code and the help. Your solution worked out great!

The this.options is above me right now although I will follow the w3 link provided by acoder to read up on it.

Whatever Samatair has in his code seems to work great.

:)
Aug 14 '08 #14
pbmods
5,821 Recognized Expert Expert
Hmm, why not this.value?
Huh. When'd they do that?

And more pertinently to my situation (unfortunately) , does IE support it?
Aug 14 '08 #15
acoder
16,027 Recognized Expert Moderator MVP
...although I will follow the w3 link provided by acoder to read up on it.
I wouldn't advise it if you're new to JavaScript. It's not an easy read.

Try some of the tutorial links in this thread in the JavaScript forum.
Aug 15 '08 #16
acoder
16,027 Recognized Expert Moderator MVP
Huh. When'd they do that?

And more pertinently to my situation (unfortunately) , does IE support it?
Since DOM Level 1, it seems, so probably around 1998.

Yes, IE does support it, but you have to ensure that the options have values. Here's something I prepared earlier :)
Aug 15 '08 #17
fjm
348 Contributor
Thanks Acoder. I will read the links you provided.

This may sound crazy, but I have always hated js and thought it was some kinda cheap wanna be language, but after getting that solution from Samatair, I am starting to change my mind. That was a perfect solution and fit very well for what I needed. Funny, but I couldn't do that with php. I know that php is server side only but one would like to think that php is possible of doing anything. :)
Aug 15 '08 #18
acoder
16,027 Recognized Expert Moderator MVP
This may sound crazy, but I have always hated js and thought it was some kinda cheap wanna be language
JavaScript did have a bad reputation and is still to some extent the world's most misunderstood programming language. Deep down, it's actually a very rich and powerful language. If you use it correctly, it's very useful, but it can also be misused.
Aug 15 '08 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1939
by: Crescionini Sascha | last post by:
Hello NG If I let appear a DIV over a HTML site with dropdowns, this dropdowns are still visible. Is there a way to push them to the back? All other form elements arent visible. greets sascha
0
916
by: Jeffrey | last post by:
Hi... I have several dropdowns located in a datagrid footer. Now say i modify the selection in dropdown1. I want to refresh the content of the other dropdowns with the result of a database query. How can i do it? Thanks Jef
3
1593
by: Damon | last post by:
I am working on a site in which I would like to have two dropdowns that will allow a user to navigate through the administrative pages of the site. The first would allow the user to choose the particular site that they would like to edit. The second would allow the user to select which admin screen they would like to edit. The second dropdown needs to be populated based on the selection in the first one. I want to encapsulate these...
1
1465
by: Andy | last post by:
What I want to do is to populate multiple dropdowns when editing. Presumably... a) I should use a DataReader so that I can get each ResultSet for each dropdown control, and that should cut down round trips to the server. b) I should populate these dropdowns in the DataGrid_EditCommand? What I am having problems with is actually referencing the dropdowns on the template. e.g. I have a dropdown called drpAccessLevels, but I cannot find this...
2
1058
by: bingomanatee | last post by:
I have developed what amounts to a fancy shopping cart wizard for a scientific instrument using VB.NET. We are having some disturbing phenomena relating to dropdown controls. On my system and other XP based systems I can repopulate the dropdowns just fine, to reflect different system configurations. However one of our engineers is runnign Windows 2000 and he has noticed that the dropdowns are showing several blank lines. They are...
0
4651
by: nkparimi | last post by:
Hi, Here's what I'm trying: given an html table, to freeze the column headers and/or left column in IE. I understand that this is possible thru style sheets in IE, as suggested in the following: http://web.tampabay.rr.com/bmerkey/examples/locked-column-csv.html http://www.adp-gmbh.ch/web/css/expression.html
3
1221
by: Simon Harvey | last post by:
Hi everyone, I keep getting a problem with dropdownlist controls. It sounds really stupid, but my app is screwed as long as this keeps happening. It seems to spontaneously happen and then I cant fix it without rebuilding the whole page from scratch! Not Fun. :-( So whats happening is I have my dropdowns on the page. The user comes along and selects an option, but when the user submits the page,. its as if nothing
1
1422
by: Stimp | last post by:
I have 3 dropdowns: country, county and district. I'm using ajax to dynamically populate the county and district dropdowns when country dropdown is changed (and similarly the district dropdown when county is changed). This works fine, but unfortunately when I reload the page (via pressing a button on the page), the county and district lists are emptied (obviously because they haven't been stored in viewstate, etc)
0
1618
by: bogorman | last post by:
Am trying to add a "video" to a webpage which is based on a template containing a javascript menu. The site has hundreds of pages all based on this template and the menu works fine The page can be viewed: www.faith.org.uk/Testindex.html In IE7 it works fine. The video shows and the dropdowns of the menu work correctly. In Mozilla Firefox, although the video works the dropdowns do not show. I have been told that everything works ok in OS...
0
971
by: sbart | last post by:
I am programing in asp.net vb using AjaxToolkit cascadingDropDown. I do not have access to AjaxToolkit cascading dropdown event handlers. I have a series of dropdowns. The selection from one of the dropdowns (call it ddA) triggers the visibility of some of the other dropdowns. Problem is that f the user makes one selection from ddA, makes selections from additonal dropdowns, then goes back and changes the selection in ddA, the selections...
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.