Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
隐藏地址字段直到输入文本-PostcodeAnywhere PHP_Php_If Statement_Postal Code - Fatal编程技术网

隐藏地址字段直到输入文本-PostcodeAnywhere PHP

隐藏地址字段直到输入文本-PostcodeAnywhere PHP,php,if-statement,postal-code,Php,If Statement,Postal Code,我想用邮政编码在任何地方建立一个地址表。搜索工作正常,并按预期自动填充字段 但是,我想找到一种方法,如何在页面上显示邮政编码字段,然后在地址输入到Address1、Address2、Town、County和Country字段中。。这些字段将显示在页面上 有没有一种简单的方法可以使用IF语句来实现这一点?PHP是否可以实时检查输入字段是否为空 到目前为止,我的表单如下所示: <li> <label>Address 1</label> <in

我想用邮政编码在任何地方建立一个地址表。搜索工作正常,并按预期自动填充字段

但是,我想找到一种方法,如何在页面上显示邮政编码字段,然后在地址输入到Address1、Address2、Town、County和Country字段中。。这些字段将显示在页面上

有没有一种简单的方法可以使用IF语句来实现这一点?PHP是否可以实时检查输入字段是否为空

到目前为止,我的表单如下所示:

<li>
    <label>Address 1</label>
    <input type="text" name="address1" value="<?php if (isset($_POST['address1'])) {echo $_POST['address1'];}?>" />(*)
</li>
<li>
    <label>Address 2</label>
    <input type="text" name="address2" value="<?php if (isset($_POST['address2'])) {echo $_POST['address2'];}?>" />
</li>
<li>
    <label>Town</label>
    <input type="text" name="town" value="<?php if (isset($_POST['town'])) {echo $_POST['town'];}?>" />
</li>
<li>
    <label>County</label>
    <input type="text" name="county" value="<?php if (isset($_POST['county'])) {echo $_POST['county'];}?>" />
</li>
<li>
    <label>Postcode</label>
    <input type="text" name="postcode" class="homeReadMo" value="<?php if (isset($_POST['postcode'])) {echo $_POST['postcode'];}?>" />
</li>
<div class="details">
    <li>
        <label>Address 1</label>
        <input type="text" name="address1" value="<?php if (isset($_POST['address1'])) {echo $_POST['address1'];}?>" />(*)
    </li>
    <li>
        <label>Address 2</label>
        <input type="text" name="address2" value="<?php if (isset($_POST['address2'])) {echo $_POST['address2'];}?>" />
    </li>
    <li>
        <label>Town</label>
        <input type="text" name="town" value="<?php if (isset($_POST['town'])) {echo $_POST['town'];}?>" />
    </li>
    <li>
        <label>County</label>
        <input type="text" name="county" value="<?php if (isset($_POST['county'])) {echo $_POST['county'];}?>" />
    </li>
</div>
<li>
    <label>Postcode</label>
    <input type="text" name="postcode" class="homeReadMo" value="<?php if (isset($_POST['postcode'])) {echo $_POST['postcode'];}?>" />
</li>
我的表格现在是这样的:

<li>
    <label>Address 1</label>
    <input type="text" name="address1" value="<?php if (isset($_POST['address1'])) {echo $_POST['address1'];}?>" />(*)
</li>
<li>
    <label>Address 2</label>
    <input type="text" name="address2" value="<?php if (isset($_POST['address2'])) {echo $_POST['address2'];}?>" />
</li>
<li>
    <label>Town</label>
    <input type="text" name="town" value="<?php if (isset($_POST['town'])) {echo $_POST['town'];}?>" />
</li>
<li>
    <label>County</label>
    <input type="text" name="county" value="<?php if (isset($_POST['county'])) {echo $_POST['county'];}?>" />
</li>
<li>
    <label>Postcode</label>
    <input type="text" name="postcode" class="homeReadMo" value="<?php if (isset($_POST['postcode'])) {echo $_POST['postcode'];}?>" />
</li>
<div class="details">
    <li>
        <label>Address 1</label>
        <input type="text" name="address1" value="<?php if (isset($_POST['address1'])) {echo $_POST['address1'];}?>" />(*)
    </li>
    <li>
        <label>Address 2</label>
        <input type="text" name="address2" value="<?php if (isset($_POST['address2'])) {echo $_POST['address2'];}?>" />
    </li>
    <li>
        <label>Town</label>
        <input type="text" name="town" value="<?php if (isset($_POST['town'])) {echo $_POST['town'];}?>" />
    </li>
    <li>
        <label>County</label>
        <input type="text" name="county" value="<?php if (isset($_POST['county'])) {echo $_POST['county'];}?>" />
    </li>
</div>
<li>
    <label>Postcode</label>
    <input type="text" name="postcode" class="homeReadMo" value="<?php if (isset($_POST['postcode'])) {echo $_POST['postcode'];}?>" />
</li>
表单字段正在被隐藏。。但是,即使Address 1字段中的文本已由PostcodeAnywhere预先填充,它们仍保持隐藏状态。有什么想法吗

已解决: 我自己用以下jQuery代码解决了这个问题:

if($('#address1').val() == "") {
        $(.details).hide();
    } else {
        $(.details).show();
    }
$('#postcode').on('change', function (event) {
if (inputHasContent($(this))) {
    $('.details').show();
} else {
    $('.details').hide();
}
});

我能够通过使用这个JS代码解决我的问题

$('#postcode').on('change', function (event) {
if (inputHasContent($(this))) {
    $('.details').show();
} else {
    $('.details').hide();
}
});

您必须使用javascript来实现这一点。使用jquery或javascript来实现这一点。但在本主题中,用户使用jquery。您已经导入jQuery了吗?此外,您可以更新您的问题并输入您尝试执行的操作。您输入的姓名邮政编码必须位于div.details中(在您的代码后面)。如果我知道你想在到达页面时隐藏邮政编码,然后在某些字段被填充时显示邮政编码。您可以使用jQuery的.keyPress()函数检查其他字段是否已填充。不,我始终希望显示邮政编码字段。当address1字段完成后,我希望address1、address2、town和county字段显示出来