【问题标题】:How to pass two javascript variables in my URL?如何在我的 URL 中传递两个 javascript 变量?
【发布时间】:2017-01-27 19:01:28
【问题描述】:

我有以下代码在拖动标记时更新页面上的 latbox/lngbox“表单字段”值:

<!---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();
            });

问题:如何将这两个值“传递”到下面的网址?

<!---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 字符串中?

【问题讨论】:

  • 丹,当单击 updateAccountLatLng“按钮”时,我正在尝试将 lat 和 lng 值传递到 url。 (见 /form 正上方的代码行)
  • 如果你现有的代码正在填充表单字段,并且表单有method =“get”,这不是提交表单的简单事情吗?

标签: javascript coldfusion


【解决方案1】:

看起来在您的 codeAddress 函数中,您希望在函数末尾有一行,根据 lat/lon 更改 queryParams

类似...

window.history.pushState('', 'title', window.location + `?lat=${lat}&amp;lon=${lon}`)

【讨论】:

  • 乔恩,你的想法是我想的方向..但是我如何将它与我的行“结合”:onclick="window.location.href='mysalesforce.com/001U000000W2Xgx/…'">
  • 您希望在调用 codeAddress() 时添加查询参数,还是仅在他们单击第二个输入时才更新?如果 #2,将 onclick=window.location.href 更改为像上面一样更改 window.history 的函数,并执行您需要它做的任何其他事情
  • 是的,当用户单击最后一个提交按钮时。出于某种原因,我无法将这两个表单字段值传递到我的 Salesforce 页面……让我发疯。
【解决方案2】:

通过执行以下操作使其正常工作:

我最终将表单 POST 更改为 GET(因为在 URL 中自动为我转发了两个表单值) 关键是将唯一的 Salesforce 字段名称(name="00NU0000003BKlJ" & name="00NU0000003BKlO")添加到我的表单字段属性中,以便 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-08
    • 2018-10-22
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2015-03-01
    • 1970-01-01
    相关资源
    最近更新 更多