duanjia1870 2018-02-04 16:16 采纳率: 0%
浏览 289

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

I try to get a value from a textbox in to a variable and show the value in the same page?

The Objective Is wen the user insert they BTC wallet in to the textbox, and i need to assign the value from the textbox in to a variable in the same page and then echo the value.

I have try this code but i get an error This is my error

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

This is my code

<!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>
  • 写回答

1条回答 默认 最新

  • douxian8883 2018-02-04 16:55
    关注

    After to read more about all type of forms i get it works. Actually it is easy but well i just start in the wrong way. Now Its Work Perfect This is the working Code

    <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>       
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机数字电压表电路组成及框图
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line