vendredi 20 novembre 2015

Want to change action of form only when 1 checkbox is selected in the form

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.

<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>";
}}
?>




Aucun commentaire:

Enregistrer un commentaire