Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

javascript - Permalink autofill Checkbox

I would like to transfer the checkboxes from one form to another form. Form #1 Form#2.

Form #1.

<form action="https://swissbutler.swissbutler.ch/checkout" method="get" enctype="multipart/form-data" autocomplete="off">
  <div class ="option-service-box4">

  <div class ="option-service">
    <label class="labl">
        <input type="checkbox" name="service" value="putzfrau-serivce" id="myCheck"/>
        <div> 
          <svg class= "icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="60" height="60">
              <g id="Outline">
                    <path d="M58.9,4.224A3,3,0,0,0,53.4,3.5L41,24.981V21a4,4,0,0,0-4-4H32V15h5a1,1,0,0,0,0-2V10a1,1,0,0,0-1-1H32a1,1,0,0,0-1,1v3a1,1,0,0,0-1,1v3.142A4,4,0,0,0,27,21v6.057a3.078,3.078,0,0,0-1.207.736,1.123,1.123,0,0,1-1.586,0,3.194,3.194,0,0,0-4.414,0A7.354,7.354,0,0,0,18.3,30H16.909L15.76,27.456a2,2,0,0,1,.823-2.555l3.958-2.285a1.992,1.992,0,0,1,2.624.565,1,1,0,0,0,1.624-1.168,3.974,3.974,0,0,0-3.563-1.64l-1.7-2.945-1.5-2.6.866-.5,3.464-2a1,1,0,0,0,.367-1.366l-2-3.464a1,1,0,0,0-1.367-.366l-3.464,2-10.392,6A1,1,0,0,0,5.134,16.5l2,3.464A1,1,0,0,0,8.5,20.33a3,3,0,0,1,4.1,1.1l1.7,2.944a3.978,3.978,0,0,0-.361,3.907L14.714,30H10a1,1,0,0,0,0,2h7.7l-.286,2H10a1,1,0,0,0,0,2h2.142l.308,2H10a1,1,0,0,0-1,1c0,10.477,8.972,19,20,19a20.554,20.554,0,0,0,12.044-3.868L40.142,60H17.858l-.485-3.152a1,1,0,0,0-1.977.3l.616,4A1,1,0,0,0,17,62H41a1,1,0,0,0,.988-.848l1.38-8.966A18.443,18.443,0,0,0,49,39a1,1,0,0,0-1-1H45.55l.308-2H48a1,1,0,0,0,1-1V31a1,1,0,0,0-1-1H45.03l3.591-6.219a1,1,0,0,0-1.732-1L42.72,30H40.412L55.134,4.5a1,1,0,1,1,1.731,1L48.889,19.317a1,1,0,1,0,1.732,1L58.6,6.5A2.986,2.986,0,0,0,58.9,4.224ZM15.83,23.026l-1-1.732,1.732-1,1.732-1,1,1.732Zm3.66-13.66,1,1.732-1.732,1-.5-.866-.5-.866Zm-9.5,8.563a4.98,4.98,0,0,0-1.575.256l-1.05-1.819,8.66-5,.5.866.5.866-.866.5a1,1,0,0,0-.366,1.366l1.5,2.6-1.1.637-2.447,1.413A5.018,5.018,0,0,0,9.991,17.929ZM29,26V24H39v2Zm4-15h2v2H33Zm-2,8h6a2,2,0,0,1,2,2v1H29V21A2,2,0,0,1,31,19ZM17.133,36,15.7,46,14.166,36Zm-4.375,4,1.3,8.434A16.258,16.258,0,0,1,11.031,40Zm34.211,0a16.258,16.258,0,0,1-3.024,8.433L45.242,40ZM47,34H35.714a1,1,0,0,0,0,2h8.12L41.493,51.218a18.706,18.706,0,0,1-24.546.38l2.541-1.525a2.509,2.509,0,0,1,2.8.145,4.536,4.536,0,0,0,5.418,0,2.509,2.509,0,0,1,2.8-.145A2.65,2.65,0,0,0,34.5,47.426L33.853,42.9a1,1,0,0,0-1.98.283l.647,4.526a.635.635,0,0,1-.285.635.629.629,0,0,1-.693.015,4.511,4.511,0,0,0-1.771-.6L29,36.929a1,1,0,1,0-2,.142l.778,10.882a4.509,4.509,0,0,0-1.271.665,2.529,2.529,0,0,1-3.018,0,4.576,4.576,0,0,0-1.11-.607l1.611-12.887a1,1,0,0,0-1.984-.248L20.4,47.73a4.524,4.524,0,0,0-1.943.628l-1.171.7,2.4-16.821a5.388,5.388,0,0,1,.192-.843l.009-.02a5.386,5.386,0,0,1,1.316-2.171,1.123,1.123,0,0,1,1.586,0,3.194,3.194,0,0,0,4.414,0,1.123,1.123,0,0,1,1.586,0,5.4,5.4,0,0,1,1.316,2.17l.009.021a5.289,5.289,0,0,1,.192.844l1,6.981a1,1,0,1,0,1.979-.284L32.3,32H47ZM31.7,30a7.356,7.356,0,0,0-1.319-2H39v.445L38.1,30Z"/>
  
  
          <div label="putzfrau" value="putzfrau-serivce" class="text">Putzfrau</div></div>
      </label>

Form #2 is the same. How can I have the marked checkboxes in Form 1 marked also in the 2nd form? With the text fields it is easy, I have the Javascript:

(new URL(window.location.href)).searchParams.forEach((x, y) =>
document.getElementById(y).value = x)

But I can’t do value = “checked” for a checkbox to select it:/

Form #1 is a different page as Form #2

Form #2 https://jsfiddle.net/MatthiasRuf/mwq9dhxb/1/#&togetherjs=bqtPPFNtRq

Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

function setChecked()
{
var allInputs = document.getElementsByTagName("input");
for (var i = 0, max = allInputs.length; i < max; i++){
    if (allInputs[i].type === 'checkbox')
        allInputs[i].checked = true;
}
}
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br> 

<button id='btn' onClick='setChecked()'>set checked</button>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...