473,394 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How can I make a field become mandatory if a certain drop down selection is made?

Hello I am trying to make a log to track questions i answer on little hardware problems. I got most of it working but I am very new to programming anything and just started picking up things. I am trying to figure out how to make it that if I select "Other" from either one of my drop downs that it makes the "Comment" text box mandatory. One of my friends said it was easy but I can't figure it out at all. PLEASE HELP.

Here is everything I have so far. Thank you in advance.

Expand|Select|Wrap|Line Numbers
  1. <table>
  2.   <tbody>
  3.     <tr>
  4.         <td>
  5.     <input type="button" name="<? echo $lc_name;?>_start_button"  id="<? echo $lc_name;?>_start_button" onclick="javascript:timeButton('<? echo $lc_name;?>_start');"  value="Start Call"/>
  6.   <input type="text" readonly="true" name="start_time" id="<? echo $lc_name;?>_start_time" /><br />
  7.             <label for="cname">Caller:</label>
  8.             <input tabindex="1" name="cname" type="text"
  9.             onkeypress="return handleEnter(this, event)"><br>
  10.  
  11.             <label for="deptCD">Dept Code:</label>
  12.             <select name="deptCD" tabindex="4"
  13.             onkeypress="return handleEnter(this, event)">
  14.             <option selected="selected" value="99">Select Dept Code</option>
  15.                 <? echo $_SESSION[$dynadeptCD]; ?>
  16.             </select><br>
  17.  
  18.             <input type="hidden" name="assocN"
  19.             value="<?PHP echo  $_SESSION['fName']." ".$_SESSION['lName']; ?>" />
  20.  
  21.             <label for="resCD">Res Code:</label>
  22.             <select name="resCD" tabindex="9"
  23.             onkeypress="return handleEnter(this, event)">
  24.                 <? echo $_SESSION[$dynaresCD]; ?>
  25.             </select><br>
  26.  
  27.             <label for="resCD2">Res Sup:</label>
  28.             <select name="resCD2" tabindex="9"
  29.             onkeypress="return handleEnter(this, event)">
  30.             <option selected="selected" value="99">Select Sup Code</option>
  31.                 <? echo $_SESSION[$dynaresCD2]; ?>
  32.             </select><br>
  33.               <label for="unnecessary">Unnecessary</label>
  34.             <input value="1" name="unnecessary" id="<?PHP echo $lc_name; ?>_CallLog_unnecessary" type="checkbox"  tabindex="11"> <label for="followUP">Follow Up</label>
  35.             <input value="1" name="followUP" id="<?PHP echo $lc_name; ?>_CallLog_followUP" type="checkbox"  tabindex="11"><br />
  36.             <input value="Submit" name="<? echo $lc_name;?>_end_button" type="submit" tabindex="12"  
  37.             id="<? echo $lc_name;?>_end_button"    
  38.             onkeypress="return handleEnter(this, event);" />
  39.             <input value="Reset" name="reset" type="reset"  tabindex="13"
  40.             onclick="clearit('<?PHP echo $lc_name; ?>_start');"
  41.             onkeypress="return handleEnter(this, event)" style="float:right"><br>
  42.         </td>
  43.  
  44.             <td >
  45.   <input type="hidden" name="new_call_id" id="new_call_id" value="<? echo md5(uniqid(time()));?>" />
  46.     <input type="hidden" name="end_time" id="<? echo $lc_name;?>_end_time" value="" />
  47.             <label for="comment">Enter A Comment:</label>
  48.             <textarea name="comment" cols="35" rows="14" id="comment"  tabindex="10"
  49.             onfocus="javascript:this.form.comment.focus();this.form.comment.select();"
  50.             > </textarea>
  51.  
  52.             <input value="<?PHP echo $nav; ?>" name="nav" type="hidden">
  53.             <input value="CallLog" name="section" type="hidden">
  54.             <input type="hidden" name="sourceID" value="<?PHP echo $uc_name; ?>">
  55.         </td>
  56.     </tr>
  57.   </tbody>
  58. </table>
Sep 7 '07 #1
1 2232
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

You will probably want to check when the form is submitted. Call the validation function onsubmit, e.g. [HTML]<form ... onsubmit="return yourValidationFunction();">[/HTML] In the validation function, check the value of the dropdown. If the value is selected, then check the value of comments field. If it is empty then return false.

Check out some of the links in the Offsite Links thread on form validation.
Sep 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
19
by: nazgulero | last post by:
Hello all, I wonder if anybody can give me a hint about what I have to do to get this working: I am creating a drop down box using the script below. The result is two text fields; now I want...
3
by: CSharpguy | last post by:
I have 3 drop downs that are populated from the databasem 4 of my web pages need to have this drop down, how can I trap the selection made in the drop down and popuate my grid on my form?
3
by: dshan | last post by:
Hi all, I can't find an answer to my quesiton anywhere. Given a drop-down list with USA states and other text fields I pass this information for further processing via PHP. If any of the...
1
by: MarcGA | last post by:
MS Access 2003/Win XP. I have a small table of legal entities and tax ID numbers. This table is a source for a larger tax registration table. On the larger table, the legal entity is selected from a...
3
by: amcoldspy | last post by:
Hi, am trying to create dynamic drop down boxes.. there are 3 drop down boxes. The second drop down box elements are to be update based on the selection made in the first drop down box...
9
by: Brett_A | last post by:
I have a form where the first field is a dynamic drop-down that pulls from a db (Access). The fields associated with the query are task_id, task_name and task_rate. The field has the value of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.