...

View Full Version : How to convert javascript to php coding



vijayram
01-31-2012, 09:51 AM
Hi guys,
Plz help me ("urgent...deadline tomorrow!")

<form>
<select onChange="updatecalendar(this.options)">
<script type="text/javascript">

var themonths=['January','February','March','April','May','June',
'July','August','September','October','November','December']

var todaydate=new Date()
var curmonth=todaydate.getMonth()+1 //get current month (1-12)
var curyear=todaydate.getFullYear() //get current year

function updatecalendar(theselection){
var themonth=parseInt(theselection[theselection.selectedIndex].value)+1
var calendarstr=buildCal(themonth, curyear, "main", "month", "daysofweek", "days", 0)
if (document.getElementById)
document.getElementById("calendarspace").innerHTML=calendarstr
}

document.write('<option value="'+(curmonth-1)+'" selected="yes">Current Month</option>')
for (i=0; i<12; i++) //display option for 12 months of the year
document.write('<option value="'+i+'">'+themonths[i]+' '+curyear+'</option>')


</script>
</select>

<div id="calendarspace">
<script>
//write out current month's calendar to start
document.write(buildCal(curmonth, curyear, "main", "month", "daysofweek", "days", 0))
</script>
</div>

</form>

Fou-Lu
01-31-2012, 02:50 PM
And what exactly is your question? PHP is a server side language, you cannot just convert javascript over to it directly; JS is an event driven language which in web based PHP there is no way to capture (ie: no onchange).
So the only thing PHP can do above is create the select.


$aMonths = array('January', 'February', 'March', ...);
print '<select>';
foreach ($aMonths AS $key => $month)
{
printf('<option value="%d">%s</option>', $key, $month);
}
print '</select>';

vijayram
02-01-2012, 02:52 AM
And what exactly is your question? PHP is a server side language, you cannot just convert javascript over to it directly; JS is an event driven language which in web based PHP there is no way to capture (ie: no onchange).
So the only thing PHP can do above is create the select.


$aMonths = array('January', 'February', 'March', ...);
print '<select>';
foreach ($aMonths AS $key => $month)
{
printf('<option value="%d">%s</option>', $key, $month);
}
print '</select>';

Hi,

I need server side code.my website developing php with symbony frame work.
i created monthly calender.i need code for monthly calender creation.

plz hel me.

Inigoesdr
02-01-2012, 02:59 AM
Hi,

I need server side code.my website developing php with symbony frame work.
i created monthly calender.i need code for monthly calender creation.

plz hel me.

Did you try the posted code?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum