Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

lists in PHP with Jscript!

  • 22-12-2006 07:00PM
    #1
    Closed Accounts Posts: 78 ✭✭


    Firstly, I want to thank all of you who have helped me with my first steps into php. You've really made my life much easier.

    Naturally, I have another issue I am trying to overcome and any advise (or code!!) would be greatly appreciated.

    I basically have 2 drop down lists on a form. The results of which are being taken as variables for future use. Basically users need to choose a course they want to attend and then which date would suit them!

    It's pretty basic - as follows:

    <select name="courses">
    <option value="Course1">This is course 1 </option>
    <option value="Course2">This is course 2 </option>
    <option value="Course3">This is course 3 </option>
    </select>

    <select name="date">
    <option value="11th Jan">11th January </option>
    <option value="12th Jan">12th January </option>
    <option value="13th Jan">13th January </option>
    </select>

    This is all working fine!

    However, different courses are available on differnet dates. I would really like it if the options of dates changed depending on which course they have selected in the previous drop down box. I will still need both the course and date value held as variables.

    I believe this is something that is possible but I would need to use an array via Java Script. My Java Script is about as strong as my PHP - i.e. not very.

    Any help would be massively appreciated.

    Outside of that, I hope all your Christmas dreams come true and that you all have a wonderful 2007.

    Thanks again,

    J


Comments

  • Closed Accounts Posts: 169 ✭✭akari no ryu


    You'll need to use Javascript for this, be it via ajax, object literal manipulation or just array manipulation.

    Something like
    // sample javascript
    courses =new Array("CourseDefault", "Course1", "Course2", "Course3");
    courses["CourseDefault"]=new Array("No course chosen");
    courses["Course1"]=new Array("11th Jan", "14th Jan", "17th Jan");
    courses["Course1"]=new Array("12th Jan", "15th Jan", "18th Jan");
    courses["Course1"]=new Array("13th Jan", "16th Jan", "19th Jan");
    
    function changeCourse(form){
      form.dates.innerHTML="";
      for(i=0; i<courses[form.course].length; i++){
        option=document.createElement('option');
        option.value=courses[form.course];
        option.appendChild(document.createTextNode(courses[form.course]);
        form.dates.appendChild(option);
      }
    }
    
    <!-- sample html -->
    <form>
     <select name="course" onchange="changeCourse(this.form)">
      <option value="CourseDefault">Choose a course</option>
      <option value="Course1">Course 1</option>
      <option value="Course2">Course 2</option>
      <option value="Course3">Course 3</option>
     </select>
     <select name="dates">
      <option value="No course chosen">No course chosen</option>
     </select>
    </form>
    

    This option is good for the simpler things, but if you have complex form structures that need vast quantities of dynamic data, then AJAX is the way to go.


Advertisement