javascript for adding number returned by combobox and date time picker

14 posts, 1 answers
  1. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 18 Feb 2011 Link to this post

    i want to add number of days returned by combobox according to selection made with my date time picker,its giving me error,object type is not supprted in javascript,and while debugging its giving me object,object in alert box.

    please help me
  2. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 18 Feb 2011 Link to this post

    again i am facing problem the date time picker is returning date string and i have to add days so how i should make formating and add.
  3. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 21 Feb 2011 Link to this post

    Hello Rahul,

    Try the following code:

    <%@ Page Language="C#" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
            <telerik:RadComboBox ID="DaysCombo" runat="server"
                OnClientSelectedIndexChanged="daysComboChanged">
                <Items>
                    <telerik:RadComboBoxItem Text=" " Value="0" />
                    <telerik:RadComboBoxItem Text="1 day" Value="1" />
                    <telerik:RadComboBoxItem Text="2 days" Value="2" />
                    <telerik:RadComboBoxItem Text="3 days" Value="3" />
                    <telerik:RadComboBoxItem Text="4 days" Value="4" />
                </Items>
            </telerik:RadComboBox>
             
            <telerik:RadDateTimePicker ID="Picker1" runat="server" SelectedDate="02/21/2011">
            </telerik:RadDateTimePicker>
     
            <script type="text/javascript">
                function daysComboChanged(sender, args)
                {
                    var days = +args.get_item().get_value();
                    var picker = $find('<%= Picker1.ClientID %>');
                    var date = new Date();
                    date.setDate(date.getDate() + days);
                    picker.set_selectedDate(date);
                }
            </script>
        </div>
        </form>
    </body>
    </html>


    Veli
    the Telerik team
  4. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 21 Feb 2011 Link to this post

    i am facing problem with the same thing,its adding year not the day
  5. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 21 Feb 2011 Link to this post

    also u r adding date +days it will return current date adding the days into that
  6. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 21 Feb 2011 Link to this post

    Do you mean the sample code I sent you is adding years instead of days, or your code does? Can you show us your code if the latter is the case.

    Veli
    the Telerik team
  7. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 21 Feb 2011 Link to this post

    function cmbJobType_SelectedIndexChanged(sender, eventArgs) {
                    var cmbJobType = $find("<%=cmbJobType.ClientID%>");
                    var i = new Date();
               
                    var item = cmbJobType.get_selectedItem();
                    var item = item.get_attributes().getAttribute("TurnaroundTime")
                    
                    var txtTargetDate = new Date();
                    var hiddenTargetDate = new Date();
                    txtTargetDate = $find("<%= txtTargetDate.ClientID%>");
                 


                    hiddenTargetDate = $find("<%= txthiddenDate.ClientID%>").get_selectedDate();


                 
                    
                    if (item != "-1" && item!=null && hiddenTargetDate!=null)
                     {
                      
                        i = hiddenTargetDate;
                      
                        
                          i.setDate(i.getDate() + item);
                       
                         
                        
                         


                       
                         
                         txtTargetDate.set_selectedDate(i);
                    }
                    else
                     {
                         txtTargetDate.set_selectedDate("");
                    }


                }



    here hidden target date is hidden field i have used to capture another date which is request receive date,now logic is to capture request receive date,add combobox value and make it target date.
  8. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 21 Feb 2011 Link to this post

    its adding year in my code...and i am facing lot of problem
  9. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 21 Feb 2011 Link to this post

     i.setDate(i.getDate() + item); this function its adding year from current date.it didnt taken the value of hiddentargetdate.and its adding year instead date also
  10. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 21 Feb 2011 Link to this post

    What is the value of item at the point at which you are adding it to the date? If it is a number, what's the type of the value? The getAttribute() method you are using to get the turnaround time returns a string. You need to parse it into a number first.

    Veli
    the Telerik team
  11. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 21 Feb 2011 Link to this post

    thanks it helped me..now i am getting exact date.thanks alot.

    one more question how to make date input hidden field
  12. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 21 Feb 2011 Link to this post

    i made visible="false" but now its not returning any value
  13. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 21 Feb 2011 Link to this post

    Do you mean you need to hide the visible textbox of the picker? You can try that:

    $find("RadDatePicker1").get_dateInput()._textBoxElement.style.display="none"


    Veli
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  14. Rahul
    Rahul avatar
    13 posts
    Member since:
    Jan 2011

    Posted 22 Feb 2011 Link to this post

    thanks it worked for me...
Back to Top