PHP on-the-fly

N

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
notes.gif

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:
 
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")
 
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:
 
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.
 
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.
 
No it's not, it's easy! Pretty much like PHP but without the "<? ?>":s and "$":s. :)
 
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. ;)
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back