[英]Javascript - How can I send the value of the text area to my textbox
I want to send the value of the text area to the textbox.我想将文本区域的值发送到文本框。 the text area value is get from the qr-code once it is scanned.
扫描后从二维码中获取文本区域值。 so i want to send the textarea value to the textbox value
所以我想将 textarea 值发送到文本框值
<?php
if(isset($_POST['btnSubcode'])) {
$lblCode = isset($_POST['lblQrTxt']) ? $_POST['lblQrTxt'] : '';
$code = $lblCode;
$code = explode(":",$code); // code = array("QR Code","444444444|123")
$code = explode("|",$code[1]); // code[1] = "444444444|123"
$code = trim($code[0]); // 444444444
$code2 = $lblCode;
$code2 = explode(":",$code2); // code = array("QR Code","444444444|123")
$code2 = explode("|",$code2[1]); // code[1] = "444444444|123"
$code2 = trim($code2[1]); // 123
}
?>
<div class="form-group">
<label class="form-control-label">code</label>
<input type="text" id="card-code" value='<?php echo $code ?>' class="form-control">
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-control-label">pin</label>
<input type="text" id="card-pin" value='<?php echo $code2 ?>' class="form-control" maxlength="3">
</div>
</div>
</form>
///////////////////////////////THIS IS THE TEXT AREA///////////////////////
<textarea class="form-control text-center" id="scanned-QR" name="lblQrTxt"></textarea><br><br>
<input class="btn btn-primary btn-lg" type="submit" name="btnSubcode"></input>
there is my code, so the value comes in the textarea.有我的代码,所以值出现在 textarea 中。 so when the value is set i want an automatic transfer on the textbox.
因此,当设置该值时,我希望在文本框上进行自动传输。
You can use jquery.您可以使用 jquery。
$("#idOfTextBox").val($("#idOfTextArea").val())
if you want to use javascript, then如果你想使用javascript,那么
document.getElementById("idOfTextBox').value =
document.getElementById("idOfTextArea').value
If I understand your question correctly, you could try something like this:如果我正确理解你的问题,你可以尝试这样的事情:
<html>
<head>
<script language="JavaScript">
function changeBack(){
document.getElementById("card-pin").value = document.getElementById("scanned-QR").value;
}
</script>
</head>
<body>
<form name="myForm">
<textarea name="myTextArea" rows=2 cols=50 onChange='changeBack()'>
Here is some text in my text area.
</textarea>
</form>
</body>
</html>
It seems you need something like this:看来你需要这样的东西:
$('#scanned-QR').on('change textInput input', function () { var val = this.value; $("input[name=input]").val(val); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <textarea class="form-control text-center" id="scanned-QR" name="lblQrTxt"></textarea><br><br> <input type="text" name = "input"></input>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.