如何在我的URL中传递两个javascript变量?
我有以下代码,在拖动标记时更新页面上的latbox/lngbox表单字段值:如何在我的URL中传递两个javascript变量?,javascript,coldfusion,Javascript,Coldfusion,我有以下代码,在拖动标记时更新页面上的latbox/lngbox表单字段值: <!---Code the Address & Lat/Long into the Info window ---> function codeAddress() { var address = document.getElementById('address').value; var account = document.getElementById('account').valu
<!---Code the Address & Lat/Long into the Info window --->
function codeAddress() {
var address = document.getElementById('address').value;
var account = document.getElementById('account').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
if (marker) {
marker.setMap(null);
if (infowindow) infowindow.close();
}
marker = new google.maps.Marker({
map: map,
draggable: true,
position: results[0].geometry.location
});
google.maps.event.addListener(marker, 'dragend', function() {
// updateMarkerStatus('Drag ended');
geocodePosition(marker.getPosition());
});
google.maps.event.addListener(marker, 'dragend', function (event) {
document.getElementById("latbox").value = this.getPosition().lat();
document.getElementById("lngbox").value = this.getPosition().lng();
});
问题:如何将这两个值传递到下面的URL
<!---Create the page to display the Account Name, Address, Geocode button to update page & Save button to save Lat/Long back into Salesforce --->
<div>
<div align="center">
<form action="" method="get">
<input name="account" type="hidden" id="account" value="<cfoutput>#URL.id1#</cfoutput>">
<input name="address" type="hidden" id="address" value="<cfoutput>#URL.id2#</cfoutput>">
<input type="button" value="Plot this customer using Physical Address" Title="Click to Map the Physical Address of Salesforce Account (if avl)"onclick="codeAddress()">
New Latitude: <input size="20" type="text" id="latbox" name="lat" >
New Longitude: <input size="20" type="text" id="lngbox" name="lng" >
<input type="button" name="updateAccountLatLng" id="updateAccountLatLng" value="Update Account?" onclick="window.location.href='https://www.mysalesforce.com/001U000000W2Xgx/e?<cfoutput>#URL.id1#</cfoutput>&00NU0000003BKlJ=javascript.latbox&00NU0000003BKlO=javascript.lngbox'">
</form>
</div>
我可以在表单字段/页面中动态显示JavaScript值,但无法将JavaScript值传递到URL字符串中?在codeAddress函数中,您希望在函数末尾有一行根据lat/lon更改查询参数 类似于
window.history.pushState'title',window.location+`?lat=${lat}&lon=${lon}`通过执行以下操作实现此功能: 我最终将表单POST更改为GET,因为GET会在URL中为我自动转发这两个表单值 关键是将唯一的Salesforce字段名称name=00num0000003bklj&name=00num0000003bklo添加到我的表单字段属性中,以便GET发布这些值。 以下是更新后的表格代码:
<!---Create the page to display the Account Name, Address, Geocode button to update page & Save button to save Lat/Long back into Salesforce --->
<div>
<div align="center">
<!---When user clicks the submit button, use GET to open the record in Salesforce and pass the new Lat/Lng values to the page --->
<form method="get" action="https://my.salesforcedomain.com/<cfoutput>#URL.id# </cfoutput>/e?">
<input name="account" type="hidden" id="account" value="<cfoutput>#URL.id1#</cfoutput>">
<input name="address" type="hidden" id="address" value="<cfoutput>#URL.id2#</cfoutput>">
<input type="button" value="Plot this customer using Physical Address" Title="Click to Map the Physical Address of Salesforce Account (if avl)"onclick="codeAddress()">
<!---Checkbox to toggle Fiber layer on/off --->
<input type="button" id="layer0" onClick="toggleLayer(0)" value="View Fiber" title="Click twice to overlay Fiber Map KML overlay(Click again to toggle on/off)">
<input type="button" id="layer1" onClick="toggleLayer(1)" value="Buildings" title="Click twice to overlay Buildings Map KML overlay(Click again to toggle on/off)">
<input type="button" id="layer2" onClick="toggleLayer(2)" value="Vaults" title="Click twice to overlay Vaults Map KML overlay(Click again to toggle on/off)">
<input type="button" id="layer3" onClick="toggleLayer(3)" value="Proposed" title="Click twice to overlay Proposed Map KML overlay(Click again to toggle on/off)">
</h2>New Latitude: <input size="20" type="text" id="latbox" name="00NU0000003BKlJ" >New Longitude: <input size="20" type="text" id="lngbox" name="00NU0000003BKlO" >
<input type="submit" name="updateAccountLatLng" id="updateAccountLatLng" value="Update Salesforce Account?" title="Click here to update the new lat/lon values to your Salesforce account.">
</form>
Dan,我试图在单击UpdateAccountLatling按钮时将lat&lng值传递到url中。查看/form正上方的代码行如果您现有的代码正在填充表单字段,并且表单具有method=get,那么提交表单怎么不简单呢?Jon,您的想法就是我想到的方向。。但是我如何将它与我的行结合起来:onclick=window.location.href=>您希望在调用codeAddress时添加查询参数,还是只希望在它们单击第二个输入时更新查询参数?如果为2,则将onclick=window.location.href更改为一个函数,该函数可以像上面一样更改window.history,并且在用户单击最后一个提交按钮时,还可以执行您需要它执行的任何操作。由于某些原因,我无法将这两个表单字段值传递到我的Salesforce页面。。。快把我逼疯了。