繁体   English   中英

如何将 html 文本框中的值分配给变量并显示在同一页面中

[英]How to assign a value from html textbox in to a variable and show in the same page

我尝试从文本框中获取一个值到一个变量中并在同一页面中显示该值?

目标是用户将他们的 BTC 钱包插入文本框中,我需要将文本框中的值分配给同一页面中的变量,然后回显该值。

我已尝试此代码,但出现错误 这是我的错误

O ficheiro não foi encontrado Pode ter sido movido ou eliminado。 ERR_FILE_NOT_FOUND

这是我的代码

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<meta name="Author" content="Helder Ventura">
<title>Roll the dice</title>
<body bgcolor="orange">
    <h1 align="center">Welcome To Dice Game</h1>
    <center>
        <form action= $Wallet method="post">
        <input type="text" size="15" name="var1" />
        <input type="submit" value="assign" />
</form>
         </center>
<?php
$var =$_POST["var1"];
// now you can do wtf you want with the variable.
echo $var;
?>

<style type="text/css">

body{
background-color:white;
font-size:10pt;
font-family:sans-serif;
color:#00436e;
}
</style>

<script language="javascript">

var d1, d2;
var ctr=0;

var images=new Array();
for(i=0;i<=6;i++){
images[i]=new Image(); images[i].src='dice'+i+'.gif';
}

function rolldice(){
document.f.t.value='';
document.f.b.value='     Rolling.....    ';
if(ctr<6){
showdice();
ctr++;
setTimeout('rolldice()',150);
}else{
ctr=0;
showdice();
document.f.t.value=d1+d2;
document.f.b.value='Roll the dice...';
}}

function showdice(){
d1=Math.floor(Math.random()*6+1);
d2=Math.floor(Math.random()*6+1);
document.images['d1'].src='dice'+d1+'.gif';
document.images['d2'].src='dice'+d2+'.gif';
}

</script>

</head>
<body>
<center>

<form name="f">
<table>
<tr height="60">
<td align="center">
<img src="dice1.gif" name="d1">
</td>
<td width="50">&nbsp;</td>
<td align="center">
<img src="dice1.gif" name="d2">
</td>
</tr>
</table>
<br><br>
<b>Roll Total</b> <input type="text" size="2" value="" name="t" readonly 
onClick="document.f.b.focus()" onSelect="document.f.b.focus()">
<br><br>
<input type="button" name="b" value="Roll the dice..." onClick="rolldice()">
</form>

</center>

<br><br><hr><br><br>

<h2>Instructions:</h2>

<form name="SAf">

<br><br><br>
 1: Copy and paste the following script in the HEAD section of your page:
<br>
<a href="javascript:document.forms['SAf'].scripttxt.focus();document.forms['SAf'].scripttxt.select();">Select all...</a>
 <br><br>
 <textarea cols="80" rows="8" wrap="off" name="scripttxt">
 &lt;script language=&quot;javascript&quot;&gt;

 var d1, d2;
 var ctr=0;

var images=new Array();
for(i=0;i<=6;i++){
images[i]=new Image(); images[i].src='dice'+i+'.gif';
}

function rolldice(){
document.f.t.value='';
document.f.b.value='     Rolling.....    ';
if(ctr<6){
showdice();
ctr++;
setTimeout('rolldice()',150);
}else{
ctr=0;
showdice();
document.f.t.value=d1+d2;
document.f.b.value='Roll the dice...';
}}

function showdice(){
d1=Math.floor(Math.random()*6+1);
d2=Math.floor(Math.random()*6+1);
document.images['d1'].src='dice'+d1+'.gif';
document.images['d2'].src='dice'+d2+'.gif';
}
&lt;/script&gt;
</textarea>

<br><br><br>
2: Copy and paste the following HTML in the BODY section of your page:
<br>
<a href="javascript:document.forms['SAf'].bodytxt.focus();document.forms['SAf'].bodytxt.select();">Select all...</a>
<br><br>
<textarea cols="80" rows="8"  wrap="off" name="bodytxt">
<form name="f">
<table>
<tr height="60">
<td align="center">
<img src="dice1.gif" name="d1">
</td>
<td width="50">&nbsp;</td>
<td align="center">
<img src="dice1.gif" name="d2">
</td>
</tr>
</table>
<br><br>
<b>Roll Total</b> <input type="text" size="2" value="" name="t" readonly 
onClick="document.f.b.focus()" onSelect="document.f.b.focus()">
<br><br>
<input type="button" name="b" value="Roll the dice..." onClick="rolldice()">
</form>
</textarea>


</form>


</body>
</html>

在阅读了有关所有类型表格的更多信息后,我得到了它的工作原理。 其实这很容易,但我只是以错误的方式开始。 现在它的工作完美 这是工作代码

<h1 align="center">Welcome To Dice Game</h1>
<center><input type="text" id="wallet" />
<input type="button" onclick="getwords()" value="Enter" />
<div id="output">
</div></center>
<script language="javascript">
function getwords(){
myOutput=document.getElementById('output');
textbox = document.getElementById('wallet');
if (textbox.value != "")

myOutput.innerHTML="You entered: " + textbox.value;
else
alert("No wallet has been entered!")
}
</script>       

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM