dougui4325 2015-11-20 11:35
浏览 30

只有在表单中选中1复选框时才想更改表单的操作

I want to submit the form and go to the action url only if one checkbox is selected.For that I used javascript as well as php. But it's not working properly.Once I select only one checkbox and preceed after that if I go back to the same page with the given code and go for the edit option again, it is not keeping a check if more than 1 or no checkbox is checked. I'm not using checkboxes because for the same form i've a delete button which can delete multiple enteries at one time

<form name="form1" method="post" action="">
<input type="submit" name="Edit"  value="Edit" />

JavaScript

<script language=Javascript>    
function changeaction()
{document.form1.action='4a2edit.php';}
</script>

Php

<?php
if(isset($_POST['Edit'])){
$checkbox = $_POST['checkbox'];
if(count($_POST['checkbox'])>1)
{
echo"<br> <Font color=red> ***More than 1 checkbox selected.Make sure that only one checkbox must be selected.***</Font>";
}
else if (count($_POST['checkbox'])==0)
{
echo"<br><Font color=red> ***No checkbox is selected.***</Font>";
}   
else
{
echo "<script language=Javascript>  
changeaction();
</script>";
}}
?>

Sorry, the missing code is :

<form name="form1" method="post" action="">
<?php
//Some php code
while($row = mysql_fetch_array($result))
{
    echo "<input name=\"checkbox[]\" type=\"checkbox\" value=".$row['ID']."> ".$row['ID'];
}
?>

<input type="submit" name="Edit"  value="Edit" />
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教