从推荐人的URL解析

问题描述 投票:1回答:1

我有下面的URL,它是一个重定向到我的Form Assembly上的表单。我试图在提交前预填隐藏字段,这样客户就不必重复填写。

state=CA&period=PERIOD_FIXED_30YEARS&贷款=200000&ltv=80&transaction=54&property_type=34&fico=740&occupancy=49&cashout=0&rate=4.125&features=510&points=0.204&trackingID=1445830871741638005。

我的代码如下。我在控制台中没有得到任何错误。

有几件事要注意:1.表单是预建的HTML,已经使用了隐藏的输入2.我需要填写的隐藏字段的ID=tfa_XX。我需要填写的隐藏字段的ID=tfa_XX。

<script type="text/javascript">

// Parsing URL
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

//Gathering the URL Parameters
var period = getParameterByName('period');
var loan = getParameterByName('loan');
var ltv = getParameterByName('ltv');
var transaction = getParameterByName('transaction');
var property_type = getParameterByName('property_type');
var fico = getParameterByName('fico');
var occupancy = getParameterByName('occupancy');
var cashout = getParameterByName('cashout');
var rate = getParameterByName('rate');
var fees = getParameterByName('fees');
var points = getParameterByName('points');
var trackingID = getParameterByName('trackingID');


function autoFill() {
//function to autoFill form
document.getElementById("tfa_49").value = period;
document.getElementById("tfa_50").value = loan;
}

</script>

谢谢您的帮助

javascript html forms url parameters
1个回答
0
投票

我可以在Form Assembly中使用下面的方法来完成这个任务。然后我导出了完整的HTML,并把它放在AEM中。

<script type="text/javascript">


//Used to pull URL
  
const link = window.location.href;
const url = new URL(link);


//Function to get the URL parameters
function getParameterByName(name) {
  return url.searchParams.get(name);
}

//Gathering the URL Parameters and writing to console to check if parse is accurate -- Note the console.log can be removed if needed
var period = getParameterByName('period');
console.log(period);

var loan = getParameterByName('loan');
console.log(loan);

var ltv = getParameterByName('ltv');
console.log(ltv);

var transaction = getParameterByName('transaction');
console.log(transaction);

var property_type = getParameterByName('property_type');
console.log(property_type);

var fico = getParameterByName('fico');
console.log(fico);

var occupancy = getParameterByName('occupancy');
console.log(occupancy);

var cashout = getParameterByName('cashout');
console.log(cashout);

var rate = getParameterByName('rate');
console.log(rate);

var fees = getParameterByName('fees');
console.log(fees);

var points = getParameterByName('points');
console.log(points);

var trackingID = getParameterByName('trackingID');
console.log(trackingID);




//On load function to prefill the forms hidden fields
$( document ).ready(function() {
  document.getElementById("tfa_49").value = period;
  document.getElementById("tfa_50").value = loan;
  document.getElementById("tfa_51").value = ltv;
  document.getElementById("tfa_53").value = transaction;
  document.getElementById("tfa_54").value = property_type;
  document.getElementById("tfa_55").value = fico;
  document.getElementById("tfa_56").value = occupancy;
  document.getElementById("tfa_57").value = cashout;
  document.getElementById("tfa_58").value = rate;
  document.getElementById("tfa_59").value = fees;
  document.getElementById("tfa_60").value = points;
  document.getElementById("tfa_61").value = trackingID;
});


</script>
© www.soinside.com 2019 - 2024. All rights reserved.