91 users online (0 members and 91 guests)  


  Results 1 to 7 of 7

Related

  1. Replies: 2
  2. javascript should be displayed in html    Forum: HTML Forum
    Replies: 0
  3. Replies: 7
  4. HTML/JavaScript/ASP    Forum: HTML Forum
    Replies: 0
  1. #1
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    javascript in html

    i have a list of values in the drop down box. i need to set a value as default.
    ie: I have a list of years. But i need to set the current year as default. how can i do that?

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: javascript in html

    Code:
    <option value="2007" selected="selected">2007</option>
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Re: javascript in html

    that is fine. But i have to give selected for the current year alone... it has to change according to the date...
    I retrieved the year in javascript..
    i alloted yr_2007 = selected in javascript after checking the condition.. i have given like this for all the variable.. but the rest of the variables will be null except for yr_2007... now i have to use this variable to set selected for the 2007 entry.. how can i do that?

  4. #4
    mschutte's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2007
    Posts
    7

    Re: javascript in html

    HTML Code:
    function BodyLoad()
    {
    myYear = 2007
    document.SELYR.value = myYear;
    }
    <body onLoad="BodyLoad();">
    <select name="SELYR">
    <option value="2007">2007</option>
    <option value="2006">2006</option>
    </select>
    </body>

  5. #5
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Re: javascript in html

    i want the current year to be displayed as default. But not that value to be passed... all the other year should also be available to the user
    for ex....
    Code:
    <select name"mysel">
    <option>2006</option>
    <option>2007></option>
    <option>2008></option>
    </select>
    i want 2007 to be the default...

    if i use
    Code:
    <select name"mysel">
    <option>2006</option>
    <option selected>2007></option>
    <option>2008></option>
    </select>
    it is some what static.. it will not change even in 2008... You understand me?
    instead i gave a javascript and retrieved the currrent year... and i used variable for each year and then using condition stored the string "selected" for yr_2007 for the year 2007. but now my problem is i am not able to set this variable to the drop down box....

    can you suggest me a solution?

  6. #6
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: javascript in html

    Hi there hermoine,

    try it like this...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    window.onload=function() {
       now=new Date();
       yy=now.getUTCFullYear();
       opt=document.forms[0].getElementsByTagName('option');
    for(c=0;c<opt.length;c++) {
    if(opt[c].value==yy){
       opt[c].selected=true;
       }
      }
     }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <div>
    <select>
    <option value="2000">2000</option>
    <option value="2001">2001</option>
    <option value="2002">2002</option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
    </select>
    </div>
    </form>
    
    </body>
    </html>

  7. #7
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Lightbulb Re: javascript in html

    i tried it in a different way...
    I set the selected index value as the year....
    that is:
    Code:
    yr=date.getFullYear();
    document.myForm.mySel.selectedIndex=yr;
    And it worked.....

    Thanks for every body who tried....



Tags for this Thread