-3

我的 html 页面有许多文本框(在显示/隐藏的 div 标签中),一旦单击底部的提交按钮,我希望它们中的数据发送到文本文档。

我对 html 编码相当陌生,并且对 php/jquery 的经验有限,所以如果有一种简单的方法可以做到这一点,我将不胜感激。这是当前代码:

我的 JS:

function showhide(layer_ref) {
    var element =  document.getElementById(layer_ref);
    var state = element.style.display

    if (state == 'block') { 
        state = 'none'; 
    } else { 
        state = 'block'; 
    } 
    if (document.all) { //IS IE 4 or 5 (or 6 beta) 
        eval( "document.all." + layer_ref + ".style.display = state"); 
    } 
    if (document.layers) { //IS NETSCAPE 4 or below 
        document.layers[layer_ref].display = state; 
    } 
    if (document.getElementById &&!document.all) { 
        hza = document.getElementById(layer_ref); 
        hza.style.display = state; 
    } 
} 

的HTML:

<form>
Name: <input type="text" name="name">
Date: <input type="numbers" name="date">

<p><a href="test.html#div1" onclick="showhide('div1');">Question 1</a></p>
<div id="div1" style="display: none;">
    <img src="q1.jpg" alt="some_text">
    <TEXTAREA Name="q1answer" ROWS=20 COLS=100></TEXTAREA>
</div> 

<!-- same code pattern for div2 to div7 -->

<p><a href="test.html#div8" onclick="showhide('div8');">Question 8</a></p> 
<div id="div8" style="display: none;">
    <img src="q8.jpg" alt="some_text">
    <TEXTAREA Name="q8answer" ROWS=20 COLS=100></TEXTAREA>
</div>

</form>
4

2 回答 2

0

You could use php GET or POST to recive data from the HTML Form.

Here is a tutorial that could help you: http://www.tizag.com/phpT/postget.php

于 2013-06-11T14:38:13.183 回答
0

将您的 HTML 表单标记更改为:

<form action='page.php' method='post'>

在表单标签末尾添加提交按钮

<input type=submit name='submit' value='submit'>

更改名称输入字段的名称标签

<input type="text" name="name">

into (你不能使用 name 作为输入的名称)

<input type="text" name="myname">

并添加此 PHP 代码:

if(isset($_POST['submit'])){ //if button is clicked do this:
    $name = $_GET['myname'];
    $date = $_GET['date'];
    $answer1 = $_GET['q1answer'];
    $answer2 = $_GET['q2answer'];
    $answer3 = $_GET['q3answer'];
    $answer4 = $_GET['q4answer'];
    $answer5 = $_GET['q5answer'];
    $answer6 = $_GET['q6answer'];
    $answer7 = $_GET['q7answer'];
    $answer8 = $_GET['q8answer'];
    }
else{
    //if button is not clicked do this
    }
于 2013-06-11T14:46:05.900 回答