简体   繁体   English

文本字符串值发布到另一页的输入字段中

[英]Textstring value post to input field in another page

I'm using Wordpress 3.8 for my site. 我在我的网站上使用Wordpress 3.8。 I want some ideas for what I am trying to achieve. 我想要一些我想要实现的想法。 Will try to explain in some simple steps: 将尝试通过一些简单的步骤进行解释:

  1. I have a domain search already installed in my site which will tell if a given domain is available or not. 我的站点中已经安装了域搜索,它将告诉您给定的域是否可用。

  2. If available, the result data (domain) will echo on the page. 如果可用,结果数据(域)将在页面上回显。

  3. Bellow the domain result a NEXT submit button is also appearing. 在域结果下面,还会出现一个NEXT提交按钮。

Now! 现在! This is where I want your ideas for a solution: 这是我希望您提出解决方案的想法:

What I want to happen now is when clicking on the input button, then the domain value will get posted to a specific field in another page. 我现在想做的是单击输入按钮时,那么域值将被发布到另一页的特定字段中。 I already got the id of that field. 我已经有了该字段的ID。

Let me here your good ideas? 让我在这里提出您的好主意吗?

Assuming your next button, calls another url, then you can assign a hash value to the url. 假设您的下一个按钮调用了另一个URL,则可以为该URL分配一个哈希值。

<a href="//nextpage/#domainname.com">NEXT</a>

Then with javascript on the next page you can grab the hash value from the url and assign it to the input box. 然后,在下一页上使用javascript,您可以从网址中获取哈希值,并将其分配给输入框。

var domainName = window.location.hash.substr(1);
$('input').val(domainName);

Tried it out, but seems to not work. 尝试了一下,但似乎不起作用。 I have already checked for script errors. 我已经检查了脚本错误。 No errors or conflicts. 没有错误或冲突。

I did like this: 我确实是这样的:

echo '<a href="http://mydomain.com/#'.$domain.'">NEXT</a>';

And then I wrote the following script just before the </head> tag and also tried to put it in the footer before the </body> tag and in the actual page: 然后,我在</head>标记之前编写了以下脚本,还尝试将其放在</body>标记之前的页脚和实际页面中:

<script>
var $domain = window.location.hash.substr(1);
jQuery('form_field_id').val($domain);
</script>

As you see above I needed to change the $ with the jQuery for resolving the error I got. 如您在上面看到的,我需要使用jQuery更改$来解决我得到的错误。

As a result, it seems to not work as the actual 'form_field_id' continues empty in the text field it self. 结果,它似乎不起作用,因为实际的“ form_field_id”在其自身的文本字段中继续为空。

Any ideas how to get around this? 任何想法如何解决这个问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM