SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    correction of code plz

    Hi guys, can any one correct my coding please, I want to create a form which ask for a month(dropdown) and year on input and onsubmit it checks if fields are valued and if so submit a page with teh calender of that month. Saterdays and sundays should have different colors, plus the user can choose anotehr month in the page of the month chosen.. This is what I've tried on my own and i just need direction , thank u...

    <html >
    <head>
    <title>Exercise1</title>
    <script type="text/javascript" src="jquery/jquery/jquery.js">
    <script type="text/javascript">
    function valid()
    {
    var field = "";
    if (!$('[name=month]').val()) field += 'month\n';
    if (!$('[name=year]').val()) field += 'year\n';

    if (field != "") {
    alert ('Please select the value\n'+field);
    return false;
    }
    return true;
    }

    </script>
    <?php
    if (!checkdate($_POST[month], 1, $_POST[year])) {
    $calArray = getdate();
    $month = $calArray['mon'];
    $year = $calArray['year'];
    } else
    {
    $month = $_POST[month];
    $year = $_POST[year];
    }
    $start = mktime (12, 0, 0, $month, 1, $year);
    $firstDayArray = getdate($start);

    $months = Array("January", "February", "March", "April", "May",

    "June", "July", "August", "September", "October", "November", "December");


    for ($x=1; $x <= count($months); $x++) {

    print "\t<calender=\"$x\"";

    print ($x == $month)?" SELECTED":"";

    print ">".$months[$x-1]."\n";

    }
    for ($x=0; $x<=2010; $x++) {
    print "\t<calender";
    print ($x == $year)?" SELECTED":"";
    print ">$x\n";
    }
    ?>
    <style>
    </style>
    </head>
    <body>
    <h3>Calender</h3>
    <form method="post" name="form" action="exercise2.php" onsubmit="return valid()">
    <select name="month"><option value=""></option>
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="6">June</option>
    <option value="7">July</option>
    <option value="8">August</option>
    <option value="9">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option>
    </select>
    Year
    <input type="text" name="year" size="4" value="">
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Please approach your teacher/tutor for your primary assistance.

    What difficulties are you having?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Soho, I did that arleay thats why i came here!!!!!thank you

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    That's a lot of code that you posted, and there is a world of advice that we might give you, most of it useless to providing what you yourself feel you actually need.

    So in light of that, what specific details are you having trouble with, and would like us to provide assistance towards?

    Answer along the lines of "just make it work" are not likely to be taken seriously.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JuliaNell View Post
    This is what I've tried on my own and i just need direction , thank u...
    Code can always be made simpler. You have a script that "doesn't work", take it apart, get the form working, get the form posting, is what is posted what is expected? yes? add the js to check the form, does it work? ... etc ... etc ...

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Basically what the guys are saying is dig through it yourself and try to understand what your code IS doing and what it is SUPPOSED to be doing.

    Whilst we're keen to assist people, we won't do their work for them

    If you have tried to fix it, outline exactly what you have done. Learning to debug is the vital step one needs to take in order to really learn computer programming.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •