View Full Version : SELECT + onChange for dynamic content change

09-22-2005, 02:25 PM
Hello guys!

I'm a php coder with not much js experience. I've searched the web & forums for a solution for my problem but I just can't get it :(

I want to reduce the number of steps on a submission page with the help of JS. The user has to choose a category (<input select... ) on one page and submit his selection. On the next page the user has to choose some other options and addtional information determined by the category.

I'm looking for a script that makes it possible to choose the category and "onChange" replaces the whole content below. The html content for each option could be stored in a variable, but consists of text and different html tags.

Is there a possibility to get this work? I've read that once a document.write is done it can't be changed... :-/ But maybe there's another way?


09-22-2005, 02:53 PM
There are a few ways.
If you only need to worry about supporting DOM browsers, you can use the AJAX technique to dyamically build elements all you want.
Simply replace content with either innerHTML or by actually creating new elements and replacing existing ones with them (createElement, replaceChild, appendChild).
No need to store all your content in a variable with the AJAX technique. You set your javascript src to a php page that dynamically writes out the javascript as desired.

09-22-2005, 03:23 PM
can you post a simple example? just a select between text1 and text2 outputting it below.

09-22-2005, 03:45 PM
Here's a tutorial on the subject specifically for PHP coders.

09-22-2005, 04:04 PM
AJAX was the keyword :)
I also found this very short tutorial:

but yours is more detailed, thats the technique I needed!

thank you :thumbsup: :thumbsup: :thumbsup: