Jump to content

Having trouble getting drop down to be required for form submission!


benjifranklin

Recommended Posts

In the code below you'll there is a .js generated submission button that submits a users radio input selection that is named "chkEpisodes[]" and what I need to do is require that at least one radio button is selected before submission, not all of them, if multiple options are generated, just one. Any help would be appreciated.

 

 

<?
/*******************************************
*  Episodes (list) (episodes.php)       
*******************************************/
@session_start();
global $cn;
include('../includes/functions.php');
include('../includes/security.php');
include('../includes/actions.php');

// Authenticated?
if($_SESSION['logged_in'] != 1)
{
$msgError = 'You must first login.';
$url = "../?msg=$msgError";
@header("Location: $url");
}

$arrPrograms = generateProductList('product_name', 'ASC');
$arrStarter  = array_keys($arrPrograms);

// Get the Program ID...
if(isset($_REQUEST['ddlProgram']))
{
$programID = $_REQUEST['ddlProgram'];
} else {
//$programID = '1';
$programID = $arrStarter[0];
}

// Set the column sorting options...
if(isset($_GET['sortColumn']))
{
$sortColumn = $_GET['sortColumn'];
$sortOrder  = $_GET['sortOrder'];
} else {
$sortColumn = 'episode_name';
$sortOrder  = 'ASC';
}

// Generate the list(s)...
$arrEpisodes = generateEpisodeList($sortColumn, $sortOrder, $programID);

//showDebug($arrPrograms);
//showDebug($_POST);
?>
<?php include("header_a.php"); ?>
  <title>Inventory | Episodes</title>
<?php include("header_b.php"); ?>

<script>
function ValidateContactForm()
{
    var name = document.ContactForm.chkEpisodes[];
  
    if (email.value == "")
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    if (email.value.indexOf("@", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    if (email.value.indexOf(".", 0) < 0)
    {
        window.alert("Please enter a valid e-mail address.");
        email.focus();
        return false;
    }
    if (comment.value == "")
    {
        window.alert("Please enter a description or comment.");
        comment.focus();
        return false;
    }
    return true;
}
</script>

		   <tr>
			<td class="layoutmenu">
			 <?
			   if($_SESSION['is_admin'] == '1')
			   {
				 include('../includes/menu_admin.php');
			   } else {
				 include('../includes/menu_client.php');
			   }
			 ?>
			</td>
			<td valign="top" align="center">
			 <img src="images/dot.gif">
			 <table width="100%" height="100%">
			  <tbody>
			   <tr>
				<td valign="top" align="center">
				 <img src="images/dot.gif" width="580" height="1">
				 <br>

  <table width="100%" cellspacing="0" cellpadding="0">
				   <tr>
					<td align="left" width="0"><b></b></td>
					<td align="left" valign="middle" style="padding-top:10px;">
					  <form name="frmPrograms" id="frmPrograms" onsubmit="return formCheck(this)" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
					   <b> Program: </b> 
					   <select name="ddlProgram" id="ddlProgram" onsubmit="return ValidateContactForm();" class="FormItemSelect" onChange="submit();">
					     <?
					      foreach($arrPrograms as $key7 => $val7)
					      {
					      	?>
							  <option value="<?=$arrPrograms[$key7]['product_id']?>" <?=(($programID == $arrPrograms[$key7]['product_id'])?('SELECTED')''))?>><?=$arrPrograms[$key7]['product_name']?></option>
							<?						      	
					      }
					     ?>
					   </select>
					  </form>
					</td>
					</tr>
					</table>

			<!-- BEGIN CONTENT -->
			<!--<script> draw_box("580",1,"List of all Episodes");</script>-->







			<table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-right: 1px solid #1A1A1A; border-left: 1px solid #1A1A1A; border-bottom: 1px solid #1A1A1A; width:580px;">
	         <tr>
   		          <td class="FormInnerBorderList">
               <table border="0" width="100%" cellpadding="0" cellspacing="0">
	            <tr>
		         <td colspan="100" class="FormSimpleListHeaderButtons">
			      <table width="100%" cellspacing="0" cellpadding="0">
				   <tr>
					<td align="left" width="0"><b></b></td>
					<!--<td align="left" valign="middle" style="padding-top:10px;">
					  <form name="frmPrograms" id="frmPrograms" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
					   <b> Program: </b> 
					   <select name="ddlProgram" id="ddlProgram" class="FormItemSelect" onChange="submit();">
					     <?
					      foreach($arrPrograms as $key7 => $val7)
					      {
					      	?>
							  <option value="<?=$arrPrograms[$key7]['product_id']?>" <?=(($programID == $arrPrograms[$key7]['product_id'])?('SELECTED')''))?>><?=$arrPrograms[$key7]['product_name']?></option>
							<?						      	
					      }
					     ?>
					   </select>
					  </form>
					</td>-->
					<td>
					 <span style="font-size:11px; color:red; font-weight:bold; font-family:arial;">  Select episodes you would like to order.</span>
					</td>
				    <td align="right">
					 <table cellspacing="0" cellpadding="0">
				  		  <tr>				
					   <td align="right">
					    <script>draw_button("order" , "javascript:document.frmEpisodes.submit();" , "" , "" , "" , "");</script>   
					</td>
					   <!--<td width="2"><img src="" width="2" height="0"></td>-->
					  </tr>
					 </table>			
					</td>
			 	   </tr>
			      </table>
	             </td>
	            </tr>
               </table>
			<table  width="100%" cellspacing="0" cellpadding="0" border="0" style="border-bottom:0px solid #91B4DD; border-top: 2px solid #1A1A1A; padding-bottom: 0px;>
			 <tr>
			  <td class="FormInnerBorderListElements">
			  <form name="frmEpisodes" id="frmEpisodes" action="./transactions_new.php" method="POST">
			   <input type="hidden" name="programID" id="programID" value="<?=$programID?>">
			   <input type="hidden" name="productID" id="productID" value="<?=$programID?>">
			   <input type="hidden" name="parentID" id="parentID" value="<?=$programID?>">
			   <input type="hidden" name="parentType" id="parentType" value="2">
			   <table border="0" width="100%" cellpadding="3" cellspacing="0" style="border-bottom: 1px solid #1A1A1A;">
                <tr>
                 <td class="FormSimpleListTitle"><img src="" width="0" height="0"> </td>
				 <!--<td class="FormSimpleListTitle"><img src="" width="0" height="0"><a title="Click here to sort this column" style="color: #000000;" href="./episodes.php?sortColumn=episode_id&sortOrder=<?=(($sortOrder == 'ASC')?('DESC')'ASC'))?>">ID</a></td> -->
                 <td class="FormSimpleListTitle"><img src="" width="0" height="0"><a title="Click here to sort this column" style="color: #000000;" href="./episodes.php?sortColumn=episode_name&sortOrder=<?=(($sortOrder == 'ASC')?('DESC')'ASC'))?>">Name</a></td> 
                 <td class="FormSimpleListTitle"><img src="" width="0" height="0"><a title="Click here to sort this column" style="color: #000000;" href="./episodes.php?sortColumn=episode_number&sortOrder=<?=(($sortOrder == 'ASC')?('DESC')'ASC'))?>">Number</a></td> 
                 <td class="FormSimpleListTitle"><img src="" width="0" height="0"><a title="Click here to sort this column" style="color: #000000;" href="./episodes.php?sortColumn=episode_format&sortOrder=<?=(($sortOrder == 'ASC')?('DESC')'ASC'))?>">Format</a></td>
                 <td class="FormSimpleListTitle"><img src="" width="0" height="0"><a title="Click here to sort this column" style="color: #000000;" href="./episodes.php?sortColumn=episode_broadcast&sortOrder=<?=(($sortOrder == 'ASC')?('DESC')'ASC'))?>">Broadcast</a></td>
                 <td class="FormSimpleListTitle"><img src="" width="0" height="0"><a title="Click here to sort this column" style="color: #000000;" href="./episodes.php?sortColumn=episode_runningtime&sortOrder=<?=(($sortOrder == 'ASC')?('DESC')'ASC'))?>">Run Time</a></td>
                 <td class="FormSimpleListTitle"><img src="" width="0" height="0"> </td> 
                </tr> 
                <!-- BEGIN DATA -->
                <?
                foreach($arrEpisodes as $key => $val)
                {
					// begin: foreach
                ?>
                <tr>
   	                 <td class="FormSimpleListCell" width="20" align="center" valign="middle"><input type="checkbox" value="<?=$key?>" name="chkEpisodes[]" id="chkEpisodes<?=$key?>"></td>
				 <!--<td class="FormSimpleListCell" width="30" align="center" valign="middle"><?=$key?></td> -->
                 <td class="FormSimpleListCell" width="" align="left" valign="middle"><?=$arrEpisodes[$key]['episode_name']?> </td> 
                 <td class="FormSimpleListCell" width="" align="left" valign="middle"><?=$arrEpisodes[$key]['episode_number']?> </td>
                 <td class="FormSimpleListCell" width="" align="left" valign="middle"><?=$arrEpisodes[$key]['episode_format']?> </td>
                 <td class="FormSimpleListCell" width="" align="left" valign="middle"><?=$arrEpisodes[$key]['episode_broadcast']?> </td>
                 <td class="FormSimpleListCell" width="" align="left" valign="middle"><?=$arrEpisodes[$key]['episode_runningtime']?> </td>
                 <td class="FormSimpleListButtons" width="1">
	              <table cellspacing="0" cellpadding="0">
		           <tr >				
			        <td>
					<?
					if($_SESSION['is_admin'] == '1')
					{
						// User is an admin...
					?>
					<script>draw_button("delete" , "./episodes.php?action=delete_episode&episodeID=<?=$key?>&ddlProgram=<?=$programID?>" , "" , "" , "" , "");</script>
					<?
					 }
					?>
					</td>
					<td width="2"><img src="" width="2" height="0"></td>
					<td><script>draw_button("details" , "./episodes_view.php?episodeID=<?=$key?>" , "" , "" , "" , "");</script></td>
					<td width="2"><img src="" width="2" height="0"></td>
		           </tr>
	              </table>
                 </td> 
                </tr>
                <?
				} // end: foreach
				?>
				<!-- END DATA -->
				</form>
	           </table>	
			  </td>
			 </tr>
			</table>
		   </td>
	      </tr>
         </table>
         <!--<script> draw_box("580",2,"List of all Episodes");</script>-->
             <!-- END CONTENT -->

<?php include("footer.php"); ?>

Link to comment
Share on other sites

Call the elements chkEpisodes without the "[]". Only one can be selected at a time if done properly. Give them all the same name, but different value attributes: 1,2,3. You don't have to set the id attribute. In the onsubmit event for the form put "return rtest();" Make a javascript function called rtest() and in the function sample formname.chkEpisodes.value. If not set, return from the function with a false value, otherwise return with a true value.

return false;

return true;

 

When false is returned within the onsubmit event, the event will be canceled. You might add an alert inside the rtest() function telling the user to select a value.

 

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.