PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
It seems like I've been struggeling with this for a while. I don't understand why the following code doesn't display 1, 2 or 3 based on the drop-down selection:
I'm afraid both answers are not what I want. I want the drop-down to say "Option1", etc. but then I want the page to automatically update based on the selection without the user having to click a button or refresh the page. In other words, I want to achieve the same effect from the last post WITHOUT the button. Is that possible?
It is possible but you have to use javascript or something like that for things like that. Php only executes on the servers computer whereas javascript (and a few other scripting languages) execute on the users computer depending on their actions.
I assume you want the user for example to select a car model (eg. Ford, Holden, Nissan etc) and when they select that, another combo box has a selection of different models for that particular car??
Just did a quick google search but couldn't find anything useful; but I'd say javascript is the way to go
I got it to work, except I guess you need to have the updated text shown in a text box. Does anyone know how to modify this so that the user is unable to edit the textbox?
PHP is a server-side language. Anytime your question relates to the processing of code/data that does not involve submitting, linking or refreshing a page, the answer will be client side. Please post Client Side related topics in the Client Side forum.
To answer your question, you are going to need to have a look at the selectedIndex property of Javascript. I would suggest you google the terms 'select list javascript' and see what comes up. Essentially you need to tell JavaScript to do something using the onChange event of the select form name/id. Then, JavaScript will need to utilize the SelectedIndex property of the passed form value to do what you want to do. This is not exactly it, but something along the lines of...
fd9 wrote:Does anyone know how to modify this so that the user is unable to edit the textbox?
There are a number of excellent sites on the web that contain this kind of reference information about each HTML tag, CSS attribute, DOM, Javascript function, etc. -- http://www.w3schools.com is one example.