Page 1 of 1

Error Checking

Posted: Wed Jul 04, 2012 6:06 am
by steve
I am using this script to create condition drop down boxes

Code: Select all

<script language="javascript" type="text/javascript">

        function dropdownlist(listindex)

        {

        document.form1.subcategory.options.length = 0;

        switch (listindex)

        {

        case "Home Ware" :

        document.form1.subcategory.options[0]=new Option("Select Sub-Category","");

        document.form1.subcategory.options[1]=new Option("Air-Conditioners/Coolers","Air-Conditioners/Coolers");

        document.form1.subcategory.options[2]=new Option("Audio/Video","Audio/Video");

        document.form1.subcategory.options[3]=new Option("Beddings","Beddings");

        document.form1.subcategory.options[4]=new Option("Camera","Camera");

        document.form1.subcategory.options[5]=new Option("Cell Phones","Cell Phones");

        break;

        case "Education" :

        document.form1.subcategory.options[0]=new Option("Select Sub-Category","");

        document.form1.subcategory.options[1]=new Option("Colleges","Colleges");

        document.form1.subcategory.options[2]=new Option("Institutes","Institutes");

        document.form1.subcategory.options[3]=new Option("Schools","Schools");

        document.form1.subcategory.options[4]=new Option("Tuitions","Tuitions");

        document.form1.subcategory.options[5]=new Option("Universities","Universities");

        break;

        case "Books" :

        document.form1.subcategory.options[0]=new Option("Select Sub-Category","");

        document.form1.subcategory.options[1]=new Option("College Books","College Books");

        document.form1.subcategory.options[2]=new Option("Engineering","Engineering");

        document.form1.subcategory.options[3]=new Option("Magazines","Magazines");

        document.form1.subcategory.options[4]=new Option("Medicine","Medicine");

        document.form1.subcategory.options[5]=new Option("References","References");

        break;
        }
        return true;
        }
        </script>
        </head>
        <title>Dynamic Drop Down List</title>
        <body>
        <form id="form1" name="form1" method="post" action="submitform1.asp" >
        <table width="100%" border="0" >
        <tr>
        <td style="text-align:right" width="150">Category:</td>
        <td width="80%"><select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
        <option value="">Select Category</option>
        <option value="Home Ware">Home Ware</option>
        <option value="Education">Education</option>
        <option value="Books">Books</option>
        </select></td>
        </tr>
        <tr>
        <td style="text-align:right" width="150">Sub Category:
        </td>
        <td width="80%"><script type="text/javascript" language="JavaScript">
        document.write('<select name="subcategory"><option value="">Select Sub-Category</option></select>')
        </script>
        <noscript><select name="subcategory" id="subcategory" >
        <option value="">Select Sub-Category</option>
        </select>
        </noscript></td>
        </tr>
        </table>
        </form>

When you get to this part

Code: Select all

        <td width="80%"><script type="text/javascript" language="JavaScript">
        document.write('<select name="subcategory"><option value="">Select Sub-Category</option></select>')
How can I code something like this

Code: Select all

<option value="Option1" <?php if ($_SESSION['as_custom1']=="Option1") {echo 'selected="selected"';} ?>/>Option1</option>
To work with the sub/slave/secondary drop down box? I tried stealing from the hesk23 custom feilds but I was unable to make heads or tails of it.

Code: Select all

  /* Select drop-down box */
	            case 'select':

                	$cls = in_array($k,$_SESSION['iserror']) ? ' class="isError" ' : '';

					echo '
					<tr>
					<td style="text-align:right" width="150">'.$v['name'].': '.$v['req'].'</td>
	                <td width="80%"><select name="'.$k.'" '.$cls.'>';

	            	$options = explode('#HESK#',$v['value']);

	                foreach ($options as $option)
	                {

		            	if (strlen($k_value) == 0 || $k_value == $option)
		                {
	                    	$k_value = $option;
	                        $selected = 'selected="selected"';
		                }
	                    else
	                    {
	                    	$selected = '';
	                    }

	                	echo '<option '.$selected.'>'.$option.'</option>';
	                }

	                echo '</select></td>
					</tr>
					';
Essentially I am trying to have the secondary drop down box populated with the information the user entered before submitting the ticket that had a required field missing data.

Re: Error Checking

Posted: Wed Jul 04, 2012 8:41 am
by dr_patso
Hey Steve, I might be understanding this wrong.. But I have a timespent custom drop down and this code makes it so the selected value for that field stays when you error on another field

Code: Select all


	<td style="text-align:right" width="150" >Time Spent:<font class="important">*</font></td>
	<td width="80%"> <select name="custom3" <?php if (in_array('custom3',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('custom3',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> > 


Re: Error Checking

Posted: Wed Jul 04, 2012 8:46 am
by dr_patso
wait MY BAD....
EDIT: you showed me this, i'm understanding your problem wrong i'm sure of it.

i have this on every option for that field.

Code: Select all

<option value="0.00"<?php if ($_SESSION['as_custom3']=="0.00") {echo 'selected="selected"';} ?>/>0.00</option>
	<option value="0.25"<?php if ($_SESSION['as_custom3']=="0.25") {echo 'selected="selected"';} ?>/>0.25</option>
	<option value="0.50"<?php if ($_SESSION['as_custom3']=="0.50") {echo 'selected="selected"';} ?>/>0.50</option>
	<option value="0.75"<?php if ($_SESSION['as_custom3']=="0.75") {echo 'selected="selected"';} ?>/>0.75</option>
	<option value="1.00"<?php if ($_SESSION['as_custom3']=="1.00") {echo 'selected="selected"';} ?>/>1.00</option>
	<option value="1.25"<?php if ($_SESSION['as_custom3']=="1.25") {echo 'selected="selected"';} ?>/>1.25</option>
	<option value="1.50"<?php if ($_SESSION['as_custom3']=="1.50") {echo 'selected="selected"';} ?>/>1.50</option>
	<option value="1.75"<?php if ($_SESSION['as_custom3']=="1.75") {echo 'selected="selected"';} ?>/>1.75</option>
	<option value="2.00"<?php if ($_SESSION['as_custom3']=="2.00") {echo 'selected="selected"';} ?>/>2.00</option>
	<option value="2.25"<?php if ($_SESSION['as_custom3']=="2.25") {echo 'selected="selected"';} ?>/>2.25</option>
	<option value="2.50"<?php if ($_SESSION['as_custom3']=="2.50") {echo 'selected="selected"';} ?>/>2.50</option>

Re: Error Checking

Posted: Wed Jul 04, 2012 3:48 pm
by steve
That works for a predefined drop down box.

But I am trying to apply the same rules/logic to the subcategory drop down box. Where there are lets say 20 different values defined by javascipt.