如何从javascript填充文本框值并执行剩余的代码 [英] How can I fill textbox value from javascript and execute the remaining code
问题描述
大家好我已经编写了一个javascript函数,我从代码后面传递3个参数我在文本框上留下了一个文本框,按钮和一个文本框,当光标位于第一个文本内时单击按钮框我想填写脚本中的第二个文本框我在按钮内调用脚本如下
< script type = text / javascript > 跨度>
功能getEndDate2(noOfWeeks,sEmployeeWeeklyOfDay,DateStart){
//我的脚本代码
}
<跨度类=代码关键字>< asp:TextBox ID = txtString runat = 服务器 > < / asp:TextBox >
< br / >
< asp:TextBox ID = TextBox1 runat = server > < / asp:TextBox >
< asp:按钮 ID = btnClick runat = server 文本 = 传递 OnClick = btnClick_Click / >
protected void btnClick_Cl ick(object sender,EventArgs e)
{
int noOfweeks = Convert.ToInt16(txtString.Text);;
string sEmployeeWeeklyOfDay =Friday;
string DateStart = DateTime.Now.AddDays(3).ToString();
btnClick.Attributes.Add( 的onClick, getEndDate2( ' + noOfweeks + '' + sEmployeeWeeklyOfDay + '' + DateStart + '););
//将值插入数据库的一些代码
}
但无法显示值第二个文本框可以帮助我如何调用该脚本后立即从文本框中丢失焦点或任何方法首先填充文本框
为什么不要在OnClientClick按钮上调用它,因为你也可以用javascript做同样的事情......
例如
功能getEndDate2()
{
<跨度类= 代码关键字> VAR 跨度> noOfweeks =的document.getElementById(<跨度类= 代码串>'跨度> < span class =code-string> txtString')。innerHTML;
<跨度类= 代码关键字> VAR 跨度> sEmployeeWeeklyOfDay = <跨度类= 代码串> 跨度> <跨度类= 代码串 >星期五跨度>;
var DateStart = new Date();
DateStart.setDate(DateStart.getDate()+ 3);
的document.getElementById(<跨度类= 代码串> '跨度> <跨度类= 代码串> TextBox1的'跨度>)。<跨度类= 代码sdkkeyword > value = DateStart.getDate();
// 我的脚本代码
}
< asp:button id = btnClick runat = server text < span class =code-keyword> = 传递 onclientclick = getEndDate2() xmlns:asp = #unknown / > ; 跨度>
Hi all I have written a javascript function where I pass 3 arguments from code behind I am having a text box, button and a text box on my form on leaving text box or clicking the button when the cursor is inside the first text box I would like to fill the second text box from the script I call the script inside the button as follows
<script type="text/javascript">
function getEndDate2(noOfWeeks, sEmployeeWeeklyOfDay, DateStart) {
// My script code
}
<asp:TextBox ID="txtString" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="btnClick" runat="server" Text="Pass" OnClick="btnClick_Click" />
protected void btnClick_Click(object sender, EventArgs e)
{
int noOfweeks = Convert.ToInt16(txtString.Text);;
string sEmployeeWeeklyOfDay = "Friday";
string DateStart = DateTime.Now.AddDays(3).ToString();
btnClick.Attributes.Add("onClick", "getEndDate2('" + noOfweeks + "','" + sEmployeeWeeklyOfDay + "','" + DateStart + "');");
// Some code to insert the values to database
}
But unable to display the value in the second text box can some one help me how can I call that script Immediately after losing focus on from the text box or any method to fill the text box first
why don''t u call it on OnClientClick of button because u can able to do same thing from javascript also...
for example
function getEndDate2() { var noOfweeks = document.getElementById('txtString').innerHTML ; var sEmployeeWeeklyOfDay = "Friday"; var DateStart = new Date(); DateStart.setDate(DateStart.getDate()+3); document.getElementById('TextBox1').value = DateStart.getDate(); // My script code }
<asp:button id="btnClick" runat="server" text="Pass" onclientclick="getEndDate2()" xmlns:asp="#unknown" />
这篇关于如何从javascript填充文本框值并执行剩余的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!