Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question SELECT + onChange for dynamic content change

    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

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you post a simple example? just a select between text1 and text2 outputting it below.

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Here's a tutorial on the subject specifically for PHP coders.
    http://www.phpbuilder.com/columns/kassemi20050606.php3

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    AJAX was the keyword
    I also found this very short tutorial:
    http://rajshekhar.net/blog/archives/...-Tutorial.html

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

    thank you

    HomerJS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •