根据同一页面上的 if 条件禁用/启用 PHP 中的表单值
disabling/enabling the form values in php based on the if condition on the same page
在这里,我想做的是基于if条件的值,应该禁用总表单,我该怎么做,这是我尝试过的代码....
if ($today1 >= $saturday && $today1 <= $season1)
{
document.getElementById('season').disabled = false;
}
else if($today1 >= $startdate_offseasona1 && $today1 <= $enddate_offseasona1 )
{
document.getElementById('season').disabled = true;
}
else if($today1 >= $startdate_seasona2 && $today1 <= $season2)
{
document.getElementById(seasons).disabled = false;
}
我的表格如下:
<form action="" method="POST" id="season" name="season">
Min_Custom_League_size<input type="text" name="min_custom_league_size" size="40"/><br/>
Max_Custom_League_size:<input type="text" name="max_custom_league_size" size="40"/><br/>
Ranked_League_size:<input type="text" name="ranked_league_size" size="40"/><br/>
Screen_Capacity:<input type="text" name="screen_capacity" size="40"/><br/>
Wide_Release_Screens:<input type="text" name="wide_release_screens" size="40"/><br/>
Limited_Release_Screens:<input type="text" name="limited_release_screens" size="40"/><br/>
Starting_Auction_Budget:<input type="text" name="starting_auction_budget" size="40"/><br/>
Weekly_Auction_Allowance:<input type="text" name="weekly_auction_allowance" size="40"/><br/>
Minimum_Auction_Bid:<input type="text" name="minimum_auction_bid" size="40"/><br/>
<input type="submit" value="submit" name="submit" />
</form>
如何根据 if 条件值执行此操作...我的代码有什么问题??
你正在混合PHP(服务器端(和JavaScript(客户端(,你不能这样做。在任何情况下,您都必须禁用<input>
元素,而不是表单本身。
以下是仅使用 PHP 执行此操作的方法:
<?php
$disableForm = $today1 >= $startdate_offseasona1 && $today1 <= $enddate_offseasona1;
?>
<form action="" method="POST" id="season" name="season">
Min_Custom_League_size<input type="text" <?php if($disableForm) echo 'disabled="disabled"'?> name="min_custom_league_size" size="40"/><br/>
<!-- repeat for all input elements -->
</form>
这是一种无条件禁用输入的纯 JavaScript 方法:
<script>
window.onload = function() {
var frm = document.getElementById('season');
var inputs = frm.getElementsByTagName('input');
for(var i=0; i<inputs.length; i++) {
inputs[i].disabled = true;
}
}
</script>
注意:您在最后else if
块中也有拼写错误,它应该是disabled
,而不是diabled
。
使用它来禁用表单中的所有元素。 同样,您可以启用表单元素
var theform = document.getElementById('seasons');
for (i = 0; i < theform.length; i++) {
var formElement = theform.elements[i];
if (true) {
formElement.disabled = true;
}
}
相关文章:
- 如何根据需要在php中启用和禁用特定日期
- .post javascript with PHP 以启用 select 语句返回
- 根据同一页面上的 if 条件禁用/启用 PHP 中的表单值
- 如何使用PHP在浏览器中检查Javascript是否启用
- 在 php/javascript 中单击另一个页面中的按钮时需要启用按钮
- 如何为此启用就地编辑 code.so 我需要在 Update.php 文件中更新该值
- 使用javascript和php启用和禁用按钮
- 如果启用了javascript,则阻止php执行
- JavaScript启用按钮在php中不起作用
- JavaScript按钮启用和禁用与PHP
- 根据php中附带的复选框更改生成的文本框可见性或启用状态
- 是否有一种方法来检查是否在php或javascript中启用了流水线
- 当页面空闲时,我如何在php中启用或禁用javascript
- 是否可以使用PHP在web浏览器中启用/禁用JavaScript ?
- 我可以从PHP中查看是否启用了Java
- 检查Safari是否阻止“来自第三方和广告商”的cookie;使用javascript/php启用
- 如果javascript未启用,则停止加载PHP页面
- 如何使用PHP在webix中启用延迟加载
- 从文本文件中读取,然后决定是要禁用还是启用php中的按钮
- 使用JS或PHP检测Firefox中启用的扩展