在表格之间传递文字?这是怎么做到的? [英] Passing text between forms? How is this done?

查看:63
本文介绍了在表格之间传递文字?这是怎么做到的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我试图在文本框中输入我的名字,然后点击转移,我希望名称出现在同一页面上(即另一种形式)。这是怎么做的?

Problem: I am trying to input my name in a text box and I click on transfer and I want the name to appear on the same page (i.e. in another form). How is this done?

展开 | 选择 | Wrap | 行号

推荐答案


问题:我试图在文本框中输入我的名字,然后点击转移,我希望名称出现在同一页面上(即另一种形式)。怎么做?


< BODY>

< HTML>


< form id = " form1",action =" testing.htm" method =" post">


您的姓名:< input type =" text" name =" name" />


< / form>


< a href =" javascript :document.form2.submit();"> transfe r< / a>


< form id =" form2" ;>


***********<名称> *********************


< / form>


< / BODY>

< / HTML>
Problem: I am trying to input my name in a text box and I click on transfer and I want the name to appear on the same page (i.e. in another form). How is this done?

<BODY>
<HTML>

<form id="form1", action="testing.htm" method="post">

Your name: <input type="text" name="name"/>

</form>


<a href="javascript:document.form2.submit();">transfe r</a>


<form id="form2">

***********< name >*********************

</form>

</BODY>
</HTML>



提交表单时,您将表单字段发送到服务器。服务器无法访问您的页面,只返回一个新页面。


所以,这里的关键是做一些不同的事情。你想做的不是提交到服务器,而是用javascript劫持提交功能。


我不知道你是否使用像prototype或jQuery这样的库,但假设没有,这里是基本的想法:


正常制作表格。


[HTML]

< form id =" nameform" ...>

< input type =" text" ID = QUOT;用户名" ... />

< input type =" submit" ID = QUOT; nameSubmitBtn" ... />

< / form>


< form name =" finalform" ...>

< input type =" text" ID = QUOT; finalname" ... />

...

< / form>

[/ HTML]


然后你将添加javascript做几件事:


(1)为#nameSubmitBtn添加一个返回false的点击处理程序,以阻止表单提交(你可以也可以通过使用按钮输入而不是提交来避免问题。


(2)扩展#nameSubmitBtn的单击处理程序以获取#username的值并将其放在#finalname


在jQuery中它会是这样的(警告未经测试):

When you submit the form, you are sending the form fields off to the server. The server cannot access your page, only return a new one.

So, the key here is to do something a little differently. What you want to do is NOT submit to the server, but instead, hijack the submit functionality with javascript.

I don''t know if you are using a library like prototype or jQuery, but assuming not, here is the basic idea:

Make your forms normally.

[HTML]
<form id="nameform" ...>
<input type="text" id="username" ... />
<input type="submit" id="nameSubmitBtn" ... />
</form>

<form name="finalform" ...>
<input type="text" id="finalname" ... />
...
</form>
[/HTML]

Then you will add javascript that does a couple things:

(1) adds a click handler for #nameSubmitBtn which returns false, to stop the form from submitting (you could also avoid the problem by using a button input instead of a submit)

(2) extend the click handler for #nameSubmitBtn to take the value of #username and place it in #finalname

In jQuery it would be something like this (caution untested):

展开 | 选择 | 换行 | 行号


我尝试了以下代码,但仍然无法在文本框中输入文本并显示结果同一页,我做错了什么:
I''ve tried the following code and still I''m unable to input text in a textbox and display the result on the same page, what I'' m I doing wrong:
展开 | 选择 | Wrap | 行号


这就是我所做的,不过一旦我点击了输入框下面显示的链接,我就需要''结果''?这怎么可能?目前正在清除输入框,只显示结果?如何在同一时间显示输入和结果?
This is what I''ve done, however I need the ''result'' once I''ve clicked on the link to be displayed under the input box? How is this possiable? Currently the ''input box'' is being cleared and only the ''result'' is displayed? How do you display ''input'' and ''result'' at the ''same time''?
展开 | 选择 | Wrap | 行号


这篇关于在表格之间传递文字?这是怎么做到的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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