This is a migrated thread and some comments may be shown as answers.
javascript for adding number returned by combobox and date time picker
13 Answers 49 Views
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 18 Feb 2011, 03:46 PM
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

13 Answers, 1 is accepted

Sort by
0
Rahul
Top achievements
Rank 1
answered on 18 Feb 2011, 05:20 PM
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.
0
Veli
Telerik team
answered on 21 Feb 2011, 10:11 AM
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
0
Rahul
Top achievements
Rank 1
answered on 21 Feb 2011, 10:44 AM
i am facing problem with the same thing,its adding year not the day
0
Rahul
Top achievements
Rank 1
answered on 21 Feb 2011, 10:49 AM
also u r adding date +days it will return current date adding the days into that
0
Veli
Telerik team
answered on 21 Feb 2011, 10:51 AM
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
0
Rahul
Top achievements
Rank 1
answered on 21 Feb 2011, 10:56 AM
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.
0
Rahul
Top achievements
Rank 1
answered on 21 Feb 2011, 11:01 AM
its adding year in my code...and i am facing lot of problem
0
Rahul
Top achievements
Rank 1
answered on 21 Feb 2011, 11:28 AM
 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
0
Accepted
Veli
Telerik team
answered on 21 Feb 2011, 12:14 PM
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
0
Rahul
Top achievements
Rank 1
answered on 21 Feb 2011, 01:51 PM
thanks it helped me..now i am getting exact date.thanks alot.

one more question how to make date input hidden field
0
Rahul
Top achievements
Rank 1
answered on 21 Feb 2011, 01:53 PM
i made visible="false" but now its not returning any value
0
Veli
Telerik team
answered on 21 Feb 2011, 02:28 PM
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!
0
Rahul
Top achievements
Rank 1
answered on 22 Feb 2011, 10:25 AM
thanks it worked for me...
Asked by
Rahul
Top achievements
Rank 1
Answers by
Rahul
Top achievements
Rank 1
Veli
Telerik team
Share this question
or