使用php在下拉列表中根据用户输入动态更改html

使用php在下拉列表中根据用户输入动态更改html,php,Php,我对php完全陌生,我正在尝试动态更改用户在下拉列表中做出选择时显示的表单。我可以让下拉列表显示,但在我提交时它不会显示任何内容 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> &l

我对php完全陌生,我正在尝试动态更改用户在下拉列表中做出选择时显示的表单。我可以让下拉列表显示,但在我提交时它不会显示任何内容

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>

<title>Forms</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>

<?php
If  (!isset($_GET['userChoice']))
{ //open the if block to write the html to the screen
?>

<h1>Show your html option form</h1>

<form method="GET" action="thirdtry.php" name="userChoice">
            <select size="1" id="choice" name="choice">

                <option selected="selected">Choose which form you would like</option>
                <option value="feedback">Feedback Form </option>
                <option value="help">Help Request Form</option>

            </select>
            <input type="submit">
</form>

<?php
}//close the if block
     else{ //show feedback
        if($_GET['userChoice']=="feedback")
        {
        ?>
            <h1>Show the feedback form</h1>

            <form id="fb" name="fb"  method="post" >
    <fieldset>


        <label>First Name: 
            <br />
                <input type="text" name="fName" id="fName" />
        </label>
            <br /> 
        <label>Last Name: 
            <br />
                <input type="text" name="lName" id="lName" />
        </label>
            <br />
        <label>Street Address:  
            <br />
                <input type="text" name="address" id="address" />
        </label>
            <br />
        <label>City 
            <br />
                <input type="text" name="city" id="city" />
        </label>
            <br />
        <label>State 
            <br />
                <input type="text" name="state" id="state" />
        </label>
            <br />
            <label>Postcode 
            <br />
                <input type="text" name="postcode" id="postcode" />
        </label>
            <br />
            <label>Country 
            <br />
                <input type="text" name="country" id="country" />
        </label>
            <br />
        <label>Email Address: 
            <br />
                <input type="text" name="FromAddress" id="FromAddress" />
        </label>
        <br />
        <label>Your message:
            <br />
                <textarea name="message" rows="7" cols="30"></textarea> <br />
        </label>
            <div>How many stars would you give this site? <br />
            (We love 5 stars!)<br />
            <input type="radio" name="rating" value="1" />1<br />
            <input type="radio" name="rating" value="2" />2<br />
            <input type="radio" name="rating" value="3" />3<br />
            <input type="radio" name="rating" value="4" />4<br />
            <input type="radio" name="rating" value="5" />5<br />
            </div>
            <br />
        <input type="submit" />
        <input type="reset" />
    </fieldset>
</form>


        <?php
        }
            else
            {//must be help form
            ?>
            <h1>Show the help form</h1>
            <form id="help" method="post" >
    <fieldset>

        <label>First Name: 
            <br />
                <input type="text" name="fNameHelp" id="fNameHelp" />
        </label>
            <br /> 
        <label>Last Name: 
            <br />
                <input type="text" name="lNameHelp" id="lNameHelp" />
        </label>
            <br />
        <label>Street Address:  
            <br />
                <input type="text" name="addressHelp" id="addressHelp" />
        </label>
            <br />
        <label>City 
            <br />
                <input type="text" name="cityHelp" id="cityHelp" />
        </label>
            <br />
        <label>State 
            <br />
                <input type="text" name="stateHelp" id="stateHelp" />
        </label>
            <br />
            <label>Postcode 
            <br />
                <input type="text" name="postcodeHelp" id="postcodeHelp" />
        </label>
            <br />
            <label>Country 
            <br />
                <input type="text" name="countryHelp" id="countryHelp" />
        </label>
            <br />
        <label>Email Address: 
            <br />
                <input type="text" name="FromAddress" />
        </label>
        <br />
        <label>Your message:
            <br />
                <textarea name="messageHelp" rows="7" cols="30"> </textarea> <br />
        </label>
            <div>How Would you like to be contacted?<br />
            (Choose all that apply) <br />
            <input type="checkbox" name="ckemail" id="ckemail" value="email" onclick="return validateHelpForm()"/>email<br />
            <input type="checkbox" name="cktelephone" id="cktelephone" value="telephone" onclick="return validateHelpForm()"/>telephone<br />
            </div>
            <br />
        <input type="submit" />
        <input type="reset" />
    </fieldset>
</form>
            <?php
            }//close the if block
        }
            ?>  



</body>
</html>

形式
显示您的html选项表单
选择您想要的表单
反馈表
求助表格
显示反馈表
名字:


姓氏:

街道地址:

城市

陈述

邮政编码

国家

电邮地址:

您的留言:

你会给这个网站多少颗星
(我们喜欢五星!)
1
2
3
4
5

显示帮助表单 名字:

姓氏:

街道地址:

城市

陈述

邮政编码

国家

电邮地址:

您的留言:

您希望如何联系?
(选择所有适用项)
电子邮件
电话


您正在检查错误的变量:

If  (!isset($_GET['userChoice']))
应该是

If  (!isset($_GET['choice']))

还有,如果,为什么要大写?(这不会引起问题-这很奇怪;)

首先,您希望页面刷新,还是希望使用Javascript在不刷新的情况下动态更改页面。根据您的简要描述,我认为您希望在不刷新的情况下进行更改

作为一名“新手”,我建议您使用Jquery作为框架,而不是完整的javascript。以下是我认为你正在努力实现的目标

由于PHP是一种服务器端编程语言,因此在不刷新的情况下无法动态更改网页。Javascript和Jquery是客户端的,所以很多事情都可以在浏览器中发生,而无需刷新

//jquery/javascript///////
$('#changeme').change(function(){
var值=$('#changeme').val();
如果(值==1){
$('#dis1').show();
$('#dis2').hide();
}
else if(值==2){
$('#dis1').hide();
$('#dis2').show();
}
否则{
$('#dis1').hide();
$('#dis2').hide();
}
});
////////HTML///////
1.
2.
显示1
显示2
////////jquery/javascript///////
$('#changeme').change(function(){
var value = $('#changeme').val();
if(value ==  1){
    $('#dis1').show();
    $('#dis2').hide();
}
else if(value == 2){
    $('#dis1').hide();
    $('#dis2').show();     
}
else{
    $('#dis1').hide();
    $('#dis2').hide();
}


});

////////HTML///////
<select id="changeme">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
</select>

<div style="display:none;" id="dis1">Displaying 1</div>
<div style="display:none;" id="dis2">Displaying 2</div>