Dynamically change text box based on radio button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • linux70
    New Member
    • Nov 2006
    • 2

    Dynamically change text box based on radio button

    I have the following. Based on which radio button is checked, I want to adjust the date that is filled in for the text box. The problem I am having is that each button fills in the same date. Am I misunderstandin g what getElementById( "opt1").val ue returns? TIA

    [HTML]<html>
    <head>
    <script language="JavaS cript">

    function changeRadioButt on(iDays)
    {
    if (document.getEl ementById("opt1 ").value == 'week')
    {iDays = 7}
    else
    {iDays = 14 }

    var myDate=new Date()
    myDate.setDate( myDate.getDate( )+ iDays)

    document.getEle mentById("dateB ox").value = myDate;
    }
    </script>
    </head>
    <body>
    <input onclick="change RadioButton()" type="radio" name="priority" id="opt1" >week</input>
    <input onclick="change RadioButton()" type="radio" name="priority" id="opt2" >month</input>
    <input onclick="change RadioButton()" type="radio" name="priority" id="opt3" >year</input>
    <input type="text" id="dateBox" value=""/>
    </body>
    </html>[/HTML]
    Last edited by acoder; Nov 13 '07, 09:20 AM. Reason: Added code tags
  • Fisher ma
    New Member
    • Nov 2007
    • 9

    #2
    Hi...
    There's some code may be help you on the blow.
    [code=javascript]
    <html>
    <head>
    <script language="JavaS cript">

    function changeRadioButt on(el){
    var iDays;
    if (el.value == 'week'){
    iDays = 7
    }else if(el.value == 'month'){
    iDays = 14
    }else{
    iDays = 0;
    }

    var myDate=new Date()
    myDate.setDate( myDate.getDate( )+ iDays)
    document.getEle mentById("dateB ox").value = myDate;
    }
    </script>
    </head>
    <body>
    <input onclick="change RadioButton(thi s)" type="radio" value="week">we ek</input>
    <input onclick="change RadioButton(thi s)" type="radio" value="month">m onth</input>
    <input onclick="change RadioButton(thi s)" type="radio" value="year">ye ar</input>
    <input type="text" id="dateBox" value=""/>
    </body>
    </html>
    [/code]

    You have't use this keyword and assign the value of input elements.

    Comment

    Working...