...

View Full Version : SELECT + onChange for dynamic content change



HomerJS
09-22-2005, 01: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?

HomerJS

nikkiH
09-22-2005, 01: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.

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

nikkiH
09-22-2005, 02:45 PM
Here's a tutorial on the subject specifically for PHP coders.
http://www.phpbuilder.com/columns/kassemi20050606.php3

HomerJS
09-22-2005, 03:04 PM
AJAX was the keyword :)
I also found this very short tutorial:
http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html

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

thank you :thumbsup: :thumbsup: :thumbsup:

HomerJS



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum