javascript - How to call function from textbox using asp.net? -
i have been trying call function formatdate()
. try put text = ""
/ value = ""
doesn't return correctly.
how can fix this?
<asp:content id="content1" contentplaceholderid="contentplaceholder1 runat="server"> <script type="text/javascript"> function formatdate(date) { var d = new date(date), month = '' + (d.getmonth() + 1), day = '' + d.getdate(), year = d.getfullyear(); year = year.tostring().substr(2, 2); daterecord = [year, month].join('/'); return daterecord } </script> <h2><asp:label id="lblpagename" text="project seq code" runat="server" /></h2> <table width="625" cellpadding="0" cellspacing="1" style="margin-left:180px;"> <tr> <td> report </td> <td><asp:textbox id="txtreport" text="return formatedate(date)" runat="server" width="250px" /> </td> </tr> </table> </asp:content>
this might solution problem. haven't tested out, i'm working same thing. i'm doing other way around, using html inputs jquery , asp server side code access controls well.
<asp:content id="content1" contentplaceholderid="contentplaceholder1 runat="server"> <script type="text/javascript"> function formatdate(date) { var d = new date(date), month = '' + (d.getmonth() + 1), day = '' + d.getdate(), year = d.getfullyear(); year = year.tostring().substr(2, 2); daterecord = [year, month].join('/'); $("#txtreport").val(daterecord); } </script> <h2><asp:label id="lblpagename" text="project seq code" runat="server" /></h2> <table width="625" cellpadding="0" cellspacing="1" style="margin-left:180px;"> <tr> <td> report </td> <td><asp:textbox id="txtreport" clientidmode="static" runat="server" width="250px" /> </td> </tr> </table> </asp:content>
instead of calling function place text (which don't know if possible, be), try placing text jquery.
you might need change asp control this:
<asp:textbox id="txtreport" clientidmode="static" runat="server" width="250px"></asp:textbox>
clientidmode make sure id assigned element used, instead of generated id asp.
edit tested , code. works without problem, difference "date" variable hard-coded because needed example. included link jquery , put scripting code in header. wanted?
<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="webapplication1.default" %> <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script> <script type="text/javascript"> var date = "02/03/1994"; var d = new date(date), month = '' + (d.getmonth() + 1), day = '' + d.getdate(), year = d.getfullyear(); year = year.tostring().substr(2, 2); var daterecord = [year, month].join('/'); //placing date jquery $(document).ready(function () { $("#txtreport").val(daterecord + " - done jquery"); }); //placing date pure javascript window.addeventlistener("load", function() { document.getelementbyid("txtreportjs").value = daterecord + " - done pure js"; }, false); </script> </head> <body> <form id="form1" runat="server"> <h2> <asp:label id="lblpagename" text="project seq code" runat="server" /></h2> <table width="625" cellpadding="0" cellspacing="1" style="margin-left: 180px;"> <tr> <td> report </td> <td> <asp:textbox id="txtreport" clientidmode="static" runat="server" width="250px" /> <asp:textbox id="txtreportjs" clientidmode="static" runat="server" width="250px" /> </td> </tr> </table> </form> </body> </html>
edited example both jquery , pure javascript methods set text textbox ;) hope need , if so, please mark answer :)
Comments
Post a Comment