Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to pass date and time into javascript method on button onclick function ?



JavaScript
onclick='javascript: doctorAppmodel('0','7','2/12/2014','02:40 AM');'

this function does not call

JavaScript
function doctorAppmodel(appdocid, appid, date, starttime) {
       
        if (appdocid > 0) {
            $.ajax({
                type: "POST",
                url: "/Dashboard.aspx/showdoctorAppointment",
                contentType: "application/json;charset=utf-8",
                data: "{'intapp':'" + obj + "'}",
                dataType: "json",
                success: function (data) {

                },
                error: function (result) {
                    alert("Error login");
                }
            });
        } else {
            document.getElementById('<%=lbldocname_doctorApp.ClientID%>').innerText = "Dr. " + '<%=Session["DocName"]%>';

            var date = new Date(date);
            var yr = date.getFullYear();
            var mo = date.getMonth() + 1;
            var day = date.getDate();
            document.getElementById('<%=lbldate_doctorApp.ClientID%>').innerText = day + "/" + mo + "/" + yr;
            document.getElementById('<%=lbltime_doctorApp.ClientID%>').innerText = starttime;

            document.getElementById('<%=hdndocname_doctorApp.ClientID%>').value = "Dr. " + '<%=Session["DocName"]%>';
            document.getElementById('<%=hdndate_doctorApp.ClientID%>').value = mo + "/" + day + "/" + yr;
            document.getElementById('<%=hdntime_doctorApp.ClientID%>').value = starttime;
        }
    }
Posted
Updated 3-Dec-14 0:20am
v3
Comments
Rajib Mahata 3-Dec-14 5:50am    
function doctorAppmodel(appdocid, appid, date, starttime) {
debugger;
if (appdocid > 0) {
$.ajax({
type: "POST",
url: "/Dashboard.aspx/showdoctorAppointment",
contentType: "application/json;charset=utf-8",
data: "{'intapp':'" + obj + "'}",
dataType: "json",
success: function (data) {

},
error: function (result) {
alert("Error login");
}
});
} else {
document.getElementById('<%=lbldocname_doctorApp.ClientID%>').innerText = "Dr. " + '<%=Session["DocName"]%>';

var date = new Date(date);
var yr = date.getFullYear();
var mo = date.getMonth() + 1;
var day = date.getDate();
document.getElementById('<%=lbldate_doctorApp.ClientID%>').innerText = day + "/" + mo + "/" + yr;
document.getElementById('<%=lbltime_doctorApp.ClientID%>').innerText = starttime;

document.getElementById('<%=hdndocname_doctorApp.ClientID%>').value = "Dr. " + '<%=Session["DocName"]%>';
document.getElementById('<%=hdndate_doctorApp.ClientID%>').value = mo + "/" + day + "/" + yr;
document.getElementById('<%=hdntime_doctorApp.ClientID%>').value = starttime;
}
}
Thanks7872 3-Dec-14 5:53am    
Which date and time are you talking about?
Rajib Mahata 3-Dec-14 6:06am    
onclick="javascript: doctorAppmodel(0,7,2/12/2014," am=");"

this does not call function doctorAppmodel(appdocid, appid, date, starttime) function
V. 3-Dec-14 6:15am    
try removing the "javascript:" like this onclick="doctorAppmodel(0,7,2/12/2014," am=");"
Secondly, If the function is in another file, make sure the file is included. Also make sure the function is defined before calling.

You can debug javascript code in the browser normally.

Hope this helps.
Jameel VM 3-Dec-14 6:41am    
put an alert on inside the start of the function and check whether it is hit or not

1 solution

Change it to
OnClientClick="doctorAppmodel('0','7','2/12/2014','02:40 AM');"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900