Category Archives: javascript

Working with select

Having html code below:

[html]

[/html]

Set current value

[javascript]
document.getElementById(“sel”).value = 3
[/javascript]

or

[javascript]
function setSelectedIndex(s, v)
{
for ( var i = 0; i < s.options.length; i++ )
{
if ( s.options[i].value == v ) {
s.options[i].selected = true;
return;
}
}
}
[/javascript]

Javascript function to get curent date

Here is the implementation of javascript function returning the current date in dd-mmm-yyyy format

[javascript]
function getCurDate(){
var months = new Array(“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Des”);
var myDate = new Date();

return myDate.getDate() + ‘-’+ months[myDate.getMonth()] + ‘-’ + myDate.getFullYear() ;
}
[/javascript]
Hope it helps!

How to send the variable from php to html page

[php]