Basically I have created a form that picks a text and adds some extra text over in textbox after applying the conditions which required which do it perfectly. after it has been displayed, user can use the copy button to copy the link for minimizing user mistake .
Everything went great but when been test the copy function, it doesn't do the job, it doesn't have any effect.
So any suggestion for form that action is , that after load with the result able to copy the result from text box ?!
try the classic javascript solution from w3school which doesn't work when added into my code. from here : https://www.w3schools.com/howto/howto_js_copy_clipboard.asp
looking into jquery solution which is this one : https://clipboardjs.com/
and not able to make it work in the code.
<form id="form1" name="form1" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<textarea name="slcOrgLinkValue" style="width:80%;" placeholder="orignal text "><?php echo $slcOrgLinkValue; ?></textarea>
</p>
Step 2: Select the type of link you require and submit. <br/> <br/>
<p>
<select name="slcmode" size="1" id="slcmode" value='<?php echo $slcmodevalue; ?>' >
<option value="0" <?php if ($slcmodevalue == 0 ) echo 'selected' ; ?> >mode1</option>
<select name="slcmode" size="1" id="slcmode" value='<?php echo $slcmodevalue; ?>' >
<option value="1" <?php if ($slcmodevalue == 1 ) echo 'selected' ; ?> >mode2</option>
</select><input type="submit" name="converterbtn" id="converterbtn" value="Submit" onclick="myFunction(); " />
<br/>
<br/>
Step 3: Copy and test
</p>
<p>
<input name="ConvertedLinktxt" id="ConvertedLinktxt" cols="4000" readonly="readonly" style="width:80%; background-color:#CCC;" value=<?php echo $slcConvertedLinkValue ; ?> ></input>
<p>
<a href=<?php echo $slcConvertedLinkValue; ?> id="convertlinktextlink" Name="convertlinktextlink" target="_Blank" onclick="myFunction();" >Test Link </a>
<button onclick="myFunction();" value="submit" > Copy link </button> </p>
<button onclick="myFunction()">Copy text</button>
</form>
<script >
function myFunction() {
var copyText = document.getElementById("ConvertedLinktxt");
copyText.select();
copyText.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}
</script>
That after form generates the new text, the user can copy the text over the clipboard, so it can paste on a specific location.