-1
#!/usr/local/bin/php

<!DOCTYPE html>
<html>
<head>
<script>
function sendInfoToChart()
{
document.getElementById("firstN").innerHTML=document.getElementById("firstName").innerHTML;
}
</script>
</head>
<body>

<form action="">
First name: <input type="text" name="firstName" id="firstName"><br>

<button onclick="sendInfoToChart()"> Submit </button>
</form>
<br><br>
<table border="1" cellpadding="4" style="font-style:italic;">
        <tr><td><p id="firstN"></p></td><td>MiddleName</td><td>Last Name</td></tr>
        </body>
</html>

我正在尝试传递在文本字段中输入的单词,并在您单击按钮时将其传递给表格。我不知道如何传递它......提前感谢您的帮助!

4

3 回答 3

1

You have to use the `value property of a text box to get its text and prevent the form from submitting to see the change,.

document.getElementById("firstN").innerHTML=document.getElementById("firstName").value;
...
<button onclick="sendInfoToChart();return false;"> Submit </button>

http://jsfiddle.net/jGvZz/

于 2013-07-11T00:28:45.533 回答
1

You can store the input in a variable and use it afterwards. Note that I've used value here, instead of innerhtml:

var firstname = document.getElementById("firstName").value;

document.getElementById("firstN").innerHTML= firstname
于 2013-07-11T00:30:18.243 回答
0
You can do this using simple PHP code    
<!DOCTYPE html>
    <html>
        <head>

        </head>
        <body>

            <form action="" method="post">
                First name: <input type="text" name="firstName" id="firstName"><br>

                <input type="submit" name="submit" value="Submit"/>
            </form>
            <br><br>
            <table border="1" cellpadding="4" style="font-style:italic;">\
                <tr><td><p id="firstN">
                        <?php 
                        if (isset($_POST['submit'])) {
                                echo $_POST['firstName'];
                        } 
                        ?>
                        </p></td><td>MiddleName</td><td>Last Name</td></tr>
            </table>        
        </body>
    </html>
于 2013-07-11T03:38:47.363 回答