SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Guru Needed

    Hi. I have a database application which allows people to book a cinema. They select the date by using a Javascript controlled drop down menu.

    Code:
    <SCRIPT LANGUAGE="Javascript">
    today = new Date();
    thismonth = today.getMonth()+1;
    thisyear = today.getYear();
    thisday = today.getDate();
    montharray=new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    maxdays=montharray[thismonth-1];
    if (thismonth==2) {
    if ((thisyear/4)!=parseInt(thisyear/4)) maxdays=28;
    else maxdays=29;
    }
    thismonth = "" + thismonth
    if (thismonth.length == 1) {
    thismonth = "0" + thismonth;
    }
    document.write("<form>");
    document.write("<select name=dates value=thedate size=1>");
    for (var theday = 1; theday <= maxdays; theday++) {
    var theday = "" + theday;
    if (theday.length == 1) {
    theday = "0" + theday;
    }
    document.write("<option");
    if (theday == thisday) document.write(" selected");
    document.write(">");
    document.write( thisyear + "-" + thismonth + "-" + theday );
    }
    document.write("</select>");
    document.write("<INPUT TYPE='submit' VALUE='go'>");
    
    </SCRIPT>
    It is good because it puts the current date on the top, however, it will only show up until the end of the month, and then on the new month it flicks over, which isn't much good for people wanting to book in advance. It only needs to show say 2 weeks in advance, but I would appreciate some helping fixing it.

    Or alternatively if someone can find/write a better/new script, that would be awesome. Cheers.
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I played with your script a little

    PHP Code:
    <SCRIPT LANGUAGE="Javascript">
    today = new Date();
    thismonth today.getMonth()+1;
    thisyear today.getYear();
    thisday today.getDate();
    montharray=new Array(312931303130313130313031);

    thismonth "" thismonth
    document
    .write("<form>");
    document.write("<select name=dates value=thedate size=1>");
    maxdays GetMaxDays(thisyear,thismonth)
    intdiff PrintDaySelect(thisyear,thismonth,thisdaymaxdays,true);
    if (
    intdiff <=14){
        if (
    thismonth == 12){
           
    thisyear++;
           
    thismonth 1;
           }
        else 
    thismonth++;    
        
    PrintDaySelect(thisyear,thismonth,1,(14-intdiff),false);
        }
    document.write("</select>");
    document.write("<INPUT TYPE='submit' VALUE='go'>");

    function 
    PrintDaySelect(thisyear,thismonth,thisdaymaxdaysflagsel){
        
    thismonth += "";
        if (
    thismonth.length == 1) {
            
    thismonth "0" thismonth;
            }
        for (var 
    theday thisdaytheday <= maxdaystheday++) {
            var 
    theday "" theday;
            if (
    theday.length == 1) {
                
    theday "0" theday;
                }
            
    document.write("<option");
            if (
    theday == thisday && flagseldocument.write(" selected");
                
    document.write(">");
            
    document.writethisyear "-" thismonth "-" theday );
            }
        return(
    maxdays-thisday);
        }
    function 
    GetMaxDays(thisyear,thismonth){
        
    maxdays=montharray[thismonth-1];
        if (
    thismonth==2) {
            if ((
    thisyear/4)!=parseInt(thisyear/4)) maxdays=28;
            else 
    maxdays=29;
            }    
        return(
    maxdays);
        }
    </SCRIPT> 

  3. #3
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good work! That is exactly what I wanted. Much appreciation to you...

    Just out of interest, if I want to increase/decrease the number of days shown, do i just change:

    Code:
    if (intdiff <=14)
    that number?
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  4. #4
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Incidentally, if you're really bored and what to look at the work in progress site and the script in action, it's here:

    www.theglenbar.co.uk
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •