PHP-选择是或否,是将导致出现新输入 [英] PHP - Select yes or no, yes causes a new input to appear

查看:60
本文介绍了PHP-选择是或否,是将导致出现新输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否可行,或者从哪里开始解决,但我想创建一个带有yes或no选项的select,如果选择yes(尚未提交表单)新的日期输入出现在下面.

I'm not sure if this is possible or where to start to tackle it with, but I'm wanting to create a select with a yes or no option, which if yes is selected (form is yet to be submitted) a new date input appears below.

我认为php是必需的,但是我是编程的新手.任何指向正确方向或基本解释的观点都是理想的!

I'm thinking php is needed, but I'm very new to programming.. Any point into the right direction or basic explanation would be ideal!

到目前为止,我猜可能是这样的……

So far I'm guessing it would be something like this...

    <select name="retrieveMarriage">
            <option value='' disabled selected style='display:none;'>Are you married?</option>
            <option value="Yes">yes</option>
            <option value="No">no</option>
    </select>

php是令人困惑的部分.

With the php being the confusing part.

if($_POST['retrieveMarriage'])
  ???

先谢谢了.

推荐答案

我个人喜欢JavaScript.

I like JavaScript for that kind of stuff, personally.

<select name="retrieveMarriage" id="retrieveMarriage" onblur="myFunction()">
        <option value='' disabled selected style='display:none;'>Are you married?</option>
        <option value="Yes">yes</option>
        <option value="No">no</option>
</select>
<span id="newDate"></span>

和JavaScript:

And the JavaScript:

function myFunction(){
  var x=document.getElementById('retrieveMarriage').value;
  if(x == 'yes'){
     document.getElementById('newDate').innerHTML='<input type=text id="myNewField"/>';
     Whatever else you want to do...
  }
}

这篇关于PHP-选择是或否,是将导致出现新输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆