我想将文本区域的值发送到文本框。扫描后,将从qr代码获取文本区域值。所以我想将textarea值发送到textbox值
<?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>
有我的代码,所以值在文本区域中。因此,设置该值后,我希望在文本框上自动传输。
答案 0 :(得分:0)
您可以使用jquery。
$("#idOfTextBox").val($("#idOfTextArea").val())
如果您想使用javascript,那么
document.getElementById("idOfTextBox').value =
document.getElementById("idOfTextArea').value
答案 1 :(得分:0)
如果我正确理解了您的问题,则可以尝试执行以下操作:
<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>
答案 2 :(得分:0)
似乎您需要这样的东西:
$('#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>