如何在我的URL中传递两个javascript变量?

时间:2017-01-27 19:01:29

标签: 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').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();
            });

问题:我如何&#34;传递这两个值&#34;到我的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字符串中吗?

2 个答案:

答案 0 :(得分:1)

在你的codeAddress函数中看起来你想要一个在函数末尾的行,它根据lat / lon改变queryParams

类似......

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

答案 1 :(得分:0)

通过执行以下操作实现此目的:

我最终将表单POST更改为GET(因为我在URL中自动转发了两个表单值) 关键是将唯一的Salesforce字段名称(name =“00NU0000003BKlJ”&amp; 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>