尝试将URL参数传递给输入字段(非表单字段) [英] Trying to pass URL parameters to input fields (NOT form fields)

查看:49
本文介绍了尝试将URL参数传递给输入字段(非表单字段)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论是在SO还是通过Google,我都花了一些时间对此进行研究.但是,我找不到任何可以帮助我的东西.这是场景:

I've used some time researching this, both here on SO and through Google. However I have not been able to find anything that helps me. Here is the scenario:

我有一个页面(MP),在这里我可以将人们带到我的会员(AP).他们必须正确填写AP上的字段,这一点非常重要,否则我将不被认可.因此,我希望我的会员链接(AL)包含要传递到AP上的表单的参数.但是,问题在于AP上的表单"实际上不是表单,而是输入字段的组合.这是AP的摘录(请记住,我无法编辑此代码):

I have a page (MP), where I send people on to an affiliate (AP) of mine. It's very important that they fill out the fields on the AP correctly, else I will not get credited. Therefore I would like my affiliate link (AL) to include parameters to pass on to the form on the AP. The problem, however, is that the "form" on the AP is not actually a form, but a combination of input fields. Here is a snippet from the AP (remember I can not edit this code):

<tbody class="original">
<tr><td colspan="3"><p><strong>* required</strong></p></td></tr>
<tr>
<th width="180"><label for="affiliateID">Affiliate ID</label></th>
<td width="250"><div class="text"><input id="affiliateID" name="affID" class="text"></div></td>
</tr>
<tr>
<th width="180"><label for="txtEmail">Your e-mail address</label></th>
<td width="250"><div class="text"><input id="txtEmail" name="email" class="text"></div></td>
</tr>
<tr>
<td colspan="3">
<input id="submitInfo" class="submit" type="submit" value="Sign-up">
</td>
</tr>
</tbody>

我的问题是,通过将我的网址中的值从MP传递过来,我是否能够解决和预填充"字段#affiliateID和#txtEmail?我尝试使用: http://www.APURL.com?affiliateID=AF54728 和其他内容,但我根本无法将其预填充".仅当AP使用传统的HTML表单时才可以这样做,还是我可以某种方式将其包含在链接URL中,以便AP识别出我想将值传递给他页面上的某个字段?我在想可能有一种方法可以解决URL中输入的ID.

My question is, will I be able to address and "pre-fill" the fields #affiliateID and #txtEmail by passing the values in my url from MP? I've tried to use: http://www.APURL.com?affiliateID=AF54728 and other stuff as well, but I am simply not able to get it to "prefill". Is this only possible to do if the AP is using a traditional HTML form or will I somehow be able to include it in the linking URL, so the AP recognizes that I want to pass a value to a certain field on his page? I was thinking there might be a way to address the ID of the input in the URL.

希望有人可以在这里帮助我.

Hope someone can help me out here.

谢谢.

推荐答案

即使您的输入字段不属于表单元素,这也是可能的.这是一个设置affiliateID字段值的有效示例.

This is possible even if your input fields are not part of a form element. Here is a working example to set the value of your affiliateID field.

function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return unescape(qs[1]);
}
var inp = document.getElementById("affiliateID");
inp.value = getQuerystring("affiliateID", "no ID given");

更新:

我误解了这个问题.这不是您正在谈论的网站,并且您想知道是否可以使用URL参数更改表单值. 不可能是不可能的.但是,常见的是,这种页面的设计方式是它通过查询字符串接受参数.您应该询问网站的所有者,并询问他是否可以通过URL以某种方式传递会员ID.

Update:

I misunderstood the question. This is not your website you're talking about, and you wanted to know if it was possible to change the form values using URL parameters. This is not possible. It is, however, common, that such a page is designed in a way that it accepts parameters via query string. You should ask the site's owner and ask him if you can pass the affiliate id somehow via URL.

这篇关于尝试将URL参数传递给输入字段(非表单字段)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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