如何在不提交表单的情况下发布文本框值 [英] how to post textbox value without submitting form

查看:120
本文介绍了如何在不提交表单的情况下发布文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我正在研究一个项目,并且是php的新手.我无法理解我该怎么做.我想根据其他文本框在文本框中选择值,这意味着如果我填写id文本框den会自动命名该文本框将填充..我得到了文本框值,但不知道如何存储测试框值而不在php中提交表单
我的代码就像:---

Actually i am working on a project and i am new in php..i cant understand how i have to do.. i want to select value in textbox according to other text box means if i fill id textbox den automatically name textbox will fill.. i got the textbox value but dont know how to store testbox value without submitting form in php
my code is like:---

<pre lang="Javascript">
<script language=''JavaScript''>
function getwords(){
myOutput=document.getElementById(''output'');
textbox = document.getElementById(''c_id'');
if (textbox.value != "")
myOutput.innerHTML=textbox.value;
else
alert(''<?php echo "No word has been entered!";?>'')
}
</script>


<pre lang="PHP">
<tr>
            <td>User_ID</td>
            <td><label>
              <input name="c_id" type="text" id="words"  önChange="getwords()">
            </label></td>
          </tr>
<div id="output"></div>
          <tr>
            <td>Name </td>
            <td><label>
              <input name="fname" type="text" id="noi" >
            </label></td>
          </tr>



现在我该怎么办...请尽快回复我..
谢谢



now what i have to do...please reply me as soon as possible..
Thanks

推荐答案

尝试一下



JavaScript
Try this



JavaScript
<script language='JavaScript' type="text/javascript">
       function getwords() {


               document.getElementById('TextBox2').value = document.getElementById('TextBox1').value;

       }
   </script>



HTML(aspx)



Html (aspx)

<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />



背后的代码(aspx.cs)



Code behind (aspx.cs)

protected void Page_Load(object sender, EventArgs e)


{
TextBox1.Attributes.Add("Onblur","getwords()");
}


{
TextBox1.Attributes.Add("Onblur", "getwords()");
}

protected void Button1_Click(object sender, EventArgs e)
      {
          string test = TextBox2.Text;
      }


尝试一下,
1.双击文本框
2.set autopostback ="true"

例如:

sample.aspx
< asp:textbox id ="TextBox1" runat ="server" ontextchanged ="TextBox1_TextChanged" autopostback ="true" xmlns:asp =#unknown">


sample.aspx.cs
try this,
1.double click textbox
2.set autopostback="true"

example:

sample.aspx
<asp:textbox id="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged" autopostback="true" xmlns:asp="#unknown">


sample.aspx.cs
protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
//to pass the value of a control to another control
session["textboxvalue"]=TextBox1.Text;

        }


尝试一下
<pre lang="Javascript">
<script language="'JavaScript'">
function getwords(){
myOutput=document.getElementById('output');
textbox = document.getElementById('c_id');
if (textbox.value != "")
document.getElementById('output').value = textbox.value;
else
alert('<?php echo "No word has been entered!";?>')
}
</script>


这篇关于如何在不提交表单的情况下发布文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆