www.webdeveloper.com
Results 1 to 7 of 7

Thread: Javascript and html

  1. #1
    Join Date
    Jan 2008
    Posts
    6

    Question Javascript and html

    I am new to Javascript; just reading the tutorial. Can I use Javascript to determine the month and then take actions in html based on what month it is? If yes, how?

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    Skip to the section in the tutorial that covers the Date object.
    You can get the current date with javascript, and there is a getMonth() method that returns an integer from 0 (January) to 11 (december).

  3. #3
    Join Date
    Jan 2008
    Posts
    6
    Thank you very much, mrhoo. When a month is displayed on the calendar, I want to take actions based on what month is displayed, not based on what the current month is. For example, when April is displayed, I want the user to see all of April's events, etc. Is there a way to do this?

  4. #4
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    That would be dependent on how the calendar and the events are defined.
    Stephen

  5. #5
    Join Date
    Jan 2008
    Posts
    6
    This is in response to the response written by felgall.

    This is the HTML code that I used to display the current month of a calendar.

    <input type="text" size="20" name="monthYear" value="" class="btn">

    monthName is one of the parameters used to determine monthYear. I am thinking that I can write a JS function, setActivity(), to display activities based on what monthName is. However, I'm not sure how to get the activities in the body section of the html code.

    Hope this makes sense.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  7. #7
    Join Date
    Jan 2008
    Posts
    6
    Thanks for the link. It was very helpful. In practicing writing functions and calling them, I wrote this function.

    function writeActivities()
    {
    document.write("all of jan");
    }//writeActivities()

    I call it with writeActivities(); and everything worked as expected.

    For practicing functions with parameters, I wrote this function.

    function writeActivities(mnthName)
    {
    var y = mnthName;
    if (y=="JAN")
    {
    document.write("all of jan");
    }
    document.write("<br>the rest");
    }//writeActivities()

    When I called it with writeActivities(mnthName);, nothing happened until I put parens around mnthName in the call, writeActivities("mnthName"); .

    Do you have to use parens when you are passing a variable when calling a function just as when you pass a string of text?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles