Jump to content

Return Form if no option has been selected


mikebyrne

Recommended Posts

At present my form loads and displays all goods "Games" from the database. If the user want to edit the detail the user selects the relevent radiobutton and presses edit

 

However, at present I have no validation to return the form if the user selects NO option and presses Edit

 

How can I code this validation using javascript??

 

Ive found an example but as a noobie to javascript im not sure how to combine it with my code

 

Example

<html>
<title>Radio Button Validation</title>
<body bgcolor="#FFFFFF">

<script language="JavaScript">
<!--
function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < radio_form.radio_button.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (radio_form.radio_button[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
// If there were no selections made display an alert box 
alert("Please select a letter.")
return (false);
}
return (true);
}

-->
</script>


<form method="get" action="http://www.codeave.com/html/get.asp" 
onsubmit="return radio_button_checker()" name="radio_form">
<input type="radio" value="A" name="radio_button">A
<br>
<input type="radio" value="B" name="radio_button">B
<br>
<input type="radio" value="C" name="radio_button">C
<br>
<input type="radio" value="D" name="radio_button">D
<br>
<input type="submit" value="Submit">
</form>

</body>
</html>

 

My full code

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">

<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>

  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->


</div>

</div>
</body>
</html>

Link to comment
Share on other sites

An example of the html output from the php code is:

 

<tr align="left">
    <td><input type="radio" value="1" name="something" /></td>
    <td><a class="black">1</a></td>
    <td>Call of Duty 4: Modern Warfare</td>
    <td>50</td>

    <td>yes</td>
    <td>55.99</td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>

  <tr align="left">
    <td><input type="radio" value="2" name="something" /></td>
    <td><a class="black">2</a></td>

    <td>Assassin's Creed</td>
    <td>50</td>
    <td>yes</td>
    <td>55.99</td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>

  <tr align="left">
    <td><input type="radio" value="5" name="something" /></td>
    <td><a class="black">5</a></td>
    <td>Ace Combat 6: Fires Of Liberation</td>
    <td>50</td>
    <td>yes</td>
    <td>55.99</td>

  </tr>

<tr><td colspan="6"><hr /></td><td></tr>

  <tr align="left">
    <td><input type="radio" value="3" name="something" /></td>
    <td><a class="black">3</a></td>
    <td>The Simpsons Game</td>
    <td>50</td>

    <td>yes</td>
    <td>57.99</td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>

  <tr align="left">
    <td><input type="radio" value="4" name="something" /></td>
    <td><a class="black">4</a></td>

    <td>Need For Speed: ProStreet</td>
    <td>50</td>
    <td>yes</td>
    <td>55.99</td>
  </tr>

 

 

Link to comment
Share on other sites

My code now looks like this but I cant get it to validate

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/start.php" class="black">Order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">Sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/adminreg.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">

<!-- data start -->
<form method="post" action="edit.php">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<script type="text/javascript">
function valid(f){
var rad=f['something'], i=0, r;
while(r=rad[i++]){
if(r.checked){return true}
}
alert('Please select a radio button option');return false
}
</script>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'Game' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>

  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->


</div>

</div>
</body>
</html>

 

Link to comment
Share on other sites

Where should I call it in my code? Im trying to modify the following code into mine

 

<script type="text/javascript">
function valid(f){
var rad=f['something'], i=0, r;
while(r=rad[i++]){
if(r.checked){return true}
}
alert('Please select a radio button option');return false
}
</script>
</head>
<body>
<form action="" onsubmit="return valid(this)">
<input type="radio" name="something" value="2">
<input type="radio" name="something" value="5">
<input type="radio" name="something" value="3">
<input type="submit" value="Submit">
</form>
</body>
</html>

 

Link to comment
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample | item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>

<div id="contentBox">

<!-- logo start -->
<div id="container">
	<div class="padTop28"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- logo finish -->



<!-- menu start -->

	<div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/start.php" class="black">Order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>

		<div id="menu_text_off"><a href="../admin_files/sales.php" class="black">Sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
		<div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/adminreg.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
	<div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>

	<div id="dotted"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
	<div id="menu2">
		<div id="menu_hide"><!-- --></div>
		<div id="menu_text_off"> </div>
		<div id="menu_space1"><!-- --></div>
		<div class="clr"><!-- --></div>
  <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_on"><!-- --></div>
          <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div>
          <div id="menu_space2">
            <!-- -->
          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div>
          <div id="menu_space2">
            <!-- -->

          </div>
          <div id="menu_space1"><!-- --></div>
	  <div id="menu_off"><!-- --></div>
          <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div>
          <div class="clr">
            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
          <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        
<!-- menu finish -->



<!-- top start -->
<div id="container">

	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- top finish -->









<!-- 1px space start -->
<div id="containerBg1">
	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- 1px space finish -->



<!-- data top start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data top finish -->



<!-- data content start -->
<div id="containerBg4">

<!-- data start -->
<form action="" onsubmit="return valid(this)">
        <table width="800" align="center" border="0"  cellspacing="0" cellpadding="0">
  <tr align="left">
    <td><a href="#">SELECT</a></td>
    <td><a href="#">PRODCT NO</a></td>
    <td><a href="#">PRODUCT NAME</a></td>
    <td><a href="#">STOCK LEVEL</a></td>
    <td><a href="#">DISPLAY</a></td>
    <td><a href="#">PRICE</a></td>
  </tr>
<script type="text/javascript">
function valid(f){
var rad=f['something'], i=0, r;
while(r=rad[i++]){
if(r.checked){return true}
}
alert('Please select a radio button option');return false
}
</script>
<?php
// let's get some data
include('adminconnect.php');
$query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'Game' ";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
// loop through and display
?>

  <tr align="left">
    <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td>
    <td><a class="black"><?php echo $row['ProductNo'];?></a></td>
    <td><?php echo $row['ProductName'];?></td>
    <td><?php echo $row['Stockamount'];?></td>
    <td><?php echo $row['Display'] ;?></td>
    <td><?php echo $row['Price'];?></td>
  </tr>

<tr><td colspan="6"><hr /></td><td></tr>
<?php
}
?>
<tr><td><input type="submit" name="submit" value="Edit" /></td></tr>
</table>



</div>
<div class="clr"><!-- --></div>
<!-- data content finish -->



<!-- data btm start -->
<div id="containerBg3">

	<div class="padTop1"><!-- --></div>
	<div class="clr"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<!-- data btm finish -->



<!-- btm start -->
<div id="containerBg1">
	<div class="padTop15"><!-- --></div>
	<div class="clr"><!-- --></div>

</div>
<div class="clr"><!-- --></div>
<div id="container">
	<div id="line"><!-- --></div>
</div>
<div class="clr"><!-- --></div>
<div class="padTop16"><!-- --></div>
<div class="clr"><!-- --></div>
<!-- btm finish -->


</div>

</div>
</body>
</html>

 

This vlidates if the user doesnt click a radio button but if the user does select  an option it doesnt post to edit.php

Link to comment
Share on other sites

I fixed my code using this:

 

<form action="edit.php" onsubmit="return valid()" method="post">

...

<script type="text/javascript">

/*<![CDATA[*/

function valid(){

var rad=document.getElementsByName('something'), i=0, r;

while(r=rad[i++]){

if(r.checked){return true}

}

alert('Please select a radio button option');return false

}

/*]]>*/

</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.