0
I have a form and a button next to it. I need to copy the information in this form by just clicking on the javascript button. The form, button and function attempt of CRTL+C is this:
HTML
<label for="disable_date">URL</label>
<div class="input-group-append">
              <input
                type="text"
                class="form-control dropdown-toggle"
                id="input_url"
              />
              <span onclick="copyText(this)" >
              <button class="btn btn-outline-info" type="button">
                <i class="dripicons-copy"></i>
              </button>
            </span>
          </div>
JAVASCRIPT
copyText(element) {
          var txt = '';
            if (window.getSelection)
            txt = window.getSelection(); 
            else if (document.getSelection)
            txt = document.getSelection();
            else return;
            document.getElementById("a").value=txt;
            allCopied =document.getElementById("a").createTextRange();
            allCopied.execCommand("RemoveFormat");
            allCopied.execCommand("Copy");
          },
Hello Vitor, I wasn’t going to comment, but I must say, that’s why I don’t like w3schools
copyText.setSelectionRange(0, 99999);, is so much non-sense, it seems that those who create the examples barely know how to program in the languages of which they "document", it seems that they came across any error and put a 999999 to force solve.– Guilherme Nascimento
It’s weird, but it seems like an exception-only solution. Modern browsers don’t need that. I believe however that completes the answer, so I kept
– Vitor Ceolin
I will test, I try some Vms and emulators for cases so, after return, anyway it was rare the times I saw something good come out of w3schools, unfortunately although many people use it is not a good source, are codes that work, but in practice does not teach what each method/function does exactly and perhaps why such situations appear as this 99999 of them
– Guilherme Nascimento
Beauty, and thank you so much for the feedback!
– Vitor Ceolin