PHP on-the-fly

Discussion in 'Web Design & Coding' started by Nitris, Jan 7, 2003.

  1. Nitris

    Nitris Guest

    ok, I just started programming in PHP and need some help.
    I created a Organizer for my active desktop. There's a part on it that lets you add a new note. I have 3 drop down list to pick the month, day, and year. now i'm wondering if there is a way when I click on a new month it will change how many days listed in the next drop down list on-the-fly without reloading the page.

    here's a pic of what i mean
    [​IMG]
    I can send the PHP code if needed :)

    I did code it so if you pick Feb it will list 28 days but it wont show and when I hit reload it goes back to Jan. :huh:
     
  2. Tabula Rasa

    Tabula Rasa Stranger Than Kindness Political User

    Messages:
    3,233
    Location:
    Israel
    not a big PHP programmer myself , but i guess you can do something like this...

    if ($_POST['month'] == "January") {
    echo "the 31 days form" }
    elseif ($_POST['month'] == "February") {
    echo "the 28 days form" }

    and so on and so on.

    forgot to mention , this is writte for global variables off.
    if you have them on you can simply do

    if ($month == "January")
     
  3. Nitris

    Nitris Guest

    I'm not a good PHP programmer myself either but if I'm reading your post right, I think I already did that.

    here's the part of my code to list the date:

    echo "Day: <select border='0' name='month' style='border-width: 1;border-color: #c0c0c0;height: 18;font: verdana;font-size: 10;border-style: solid;'>";
    $day = 1;
    If ($month == Jan || Mar || May || July || Aug || Oct || Dec):
    while ($day <= 31):
    echo "<option>$day";
    $day++;
    endwhile;
    elseif ($month == Apr || June || Sep || Nov):
    while ($day <= 30):
    echo "<option>$day";
    $day++;
    endwhile;
    elseif ($month == Feb):
    while ($day <= 28):
    echo "<option>$day";
    $day++;
    endwhile;
    endif;
    echo "</select> ";

    If you can see (its kinda sloppy), it does switch the list to the right numbers of days but the page has already written the code onto it. so even though I pick Feb it will still list 31 days because the code was interpeted while the month was on Jan. what I'm tryin to do is that when I pick Feb the days list will change to 28 on-the-fly. I'm bad at explaining stuff so you might not get what I'm saying :huh:
     
  4. Tabula Rasa

    Tabula Rasa Stranger Than Kindness Political User

    Messages:
    3,233
    Location:
    Israel
    I get what you mean, the problem is i'm probably a worst programmer then you are, I never tried doing anything on-the-fly nor had a need to.

    maybe someone else around here can help you.
     
  5. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    The big problem is you can't. Not with PHP. Since PHP is run on the server you can't affect the page once it's loaded by the user. This will have to be written in Javascript instead since Javascript is run on the client side in the browser.
     
  6. aswettla

    aswettla Guest

    Yep....can't do it.
     
  7. Nitris

    Nitris Guest

    ......now i have to learn javascript :huh:
     
  8. aswettla

    aswettla Guest

    good luck..

    Javascript is hard as hell to learn
     
  9. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    No it's not, it's easy! Pretty much like PHP but without the "<? ?>":s and "$":s. :)
     
  10. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Look, I made you a script! :)

    Code:
    <SCRIPT>
    function setDays(){
    	index = document.dateform.months.selectedIndex
    	numdays = document.dateform.months.options[index].value;
    	document.dateform.days.length = numdays;
    	for(i=0;i<numdays;i++){
    		document.dateform.days.options[i] = new Option(i+1,i+1);
    	}
    }
    </SCRIPT>
    
    <FORM NAME="dateform" METHOD="post" ACTION="">
      <SELECT NAME="months" ID="months" onChange="setDays()">
        <OPTION VALUE="31">Jan</OPTION>
        <OPTION VALUE="28">Feb</OPTION>
        <OPTION VALUE="31">Mar</OPTION>
        <OPTION VALUE="30">Apr</OPTION>
    	<!-- And so on...-->
      </SELECT>
      <SELECT NAME="days" ID="days">
      	<!-- Empty for now -->
      </SELECT>
    </FORM>
    
    <SCRIPT>
    // Set the inital number of days.
    // Must be AFTER the form!
    setDays();
    </SCRIPT>
    And it works too. ;)
     
  11. Nitris

    Nitris Guest

    THX!! :happy: :happy: :happy: