473,396 Members | 1,879 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,396 software developers and data experts.

Function doesnt work with drop down

29
I'm trying to use a function that will be if A nill then B and C get a value and vice verse if B nill C and A have value and the all function meant to be called right at the top of the drop down list just like the one that says SELECT CATEGORY

Expand|Select|Wrap|Line Numbers
  1.  <html>
  2. <body>
  3.  
  4. <?php
  5.  
  6. // Create an empty array to hold the error messages.
  7. $arrErrors = array();
  8. //Only validate if the Submit button was clicked.
  9. if (!empty($_POST['Submit'])) {
  10.     // Each time there's an error, add an error message to the error array
  11.     // using the field name as the key.
  12.  
  13.         if ($_POST['campustype']=='')
  14.         $arrErrors['campustype'] = 'Please select category.';
  15.  
  16.  
  17. function Name(){
  18.  
  19.    if ($_POST['howt']=='')
  20.     {
  21.  
  22.           (isset($_POST['hot']) && isset($_POST['ho']));
  23.  
  24.       }
  25.  
  26.  
  27.  else
  28.  
  29.  
  30. if   ($_POST['hot']=='')
  31.     {
  32.  
  33.           (isset($_POST['howt']) && isset($_POST['ho']));
  34.  
  35.  
  36.      else 
  37.  
  38.   if ($_POST['ho']=='')
  39.     {
  40.  
  41.           (isset($_POST['howt']) && isset($_POST['hot']));
  42. }               
  43.  
  44.         else 
  45.  
  46.  if ($_POST['ho && howt && hot']=='')
  47.         $arrErrors['Name()'] = 'Please category.';
  48. }
  49.   if (count($arrErrors) == 0) {
  50.         // If the error array is empty, there were no errors.
  51.         // Insert form processing here.
  52.     } else {
  53.         // The error array had something in it. There was an error.
  54.         // Start adding error text to an error string.
  55.         $strError = '<div class="formerror"><p><img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again:</p><ul>';
  56.         // Get each error and add it to the error string
  57.         // as a list item.
  58.         foreach ($arrErrors as $error) {
  59.             $strError .= "<li>$error</li>";
  60.         }
  61.         $strError .= '</ul></div>';
  62.     }
  63. }
  64. ?>
  65.  
  66. <style>
  67.  
  68.  
  69. .formerror {
  70.   border: 1px solid red;
  71.   background-color : #FFCCCC;
  72.   width: auto;
  73.   padding: 5px 0;
  74. }
  75.  
  76. .errortext {
  77.   padding-left: 80px;
  78.   font-size:14px;
  79.   color:red;
  80.  
  81. }
  82.  
  83.  
  84.  
  85. </style>
  86.  
  87.  
  88. <script type="text/javascript">
  89. function toggleSelect(id)
  90. {
  91.     if (id == 'off')
  92.     {
  93.           document.getElementById('in-campu').style['display'] = 'none'; //ui
  94.           document.getElementById('1').style['display'] = 'none';
  95.           document.getElementById('off-campus').style['display'] = 'block';
  96.     }
  97.  
  98.     if (id == 'in')
  99.     {
  100.  
  101.           document.getElementById('off-campus').style['display'] = 'none';
  102.           document.getElementById('1').style['display'] = 'none';
  103.           document.getElementById('in-campu').style['display'] = 'block';//ui
  104.  
  105.     }
  106.  
  107. if (id == '1')
  108.     {
  109.           document.getElementById('off-campus').style['display'] = 'none';
  110.           document.getElementById('in-campu').style['display'] = 'none'; //ui
  111.           document.getElementById('1').style['display'] = 'block';
  112.     }
  113.  
  114.  
  115. }
  116. </script>
  117.  
  118.  
  119. <?php echo $strError; ?>
  120. <form method="post" action="<?php echo $PHP_SELF; ?>">
  121. <!--
  122. For every form field, we do the following...
  123.  
  124. Check to see if there's an error message for this form field. If there is,
  125. add the formerror class to the surrounding paragraph block. The formerror
  126. class contains the highlighted box.
  127.  
  128. Insert the contents of what the user submitted bak into the form field.
  129.  
  130. Check again to see if this field has an error message. If it does, show
  131. the error icon and the error message next to the field.
  132. -->
  133.  
  134. <p<?php if (!empty($arrErrors['campustype'])) echo ' class="formerro"'; ?>>
  135.  
  136.     <?php if (!empty($arrErrors['campustype'])) echo '<br /><span class="errortext">'.$arrErrors['campustype'].'</span>'; ?><br/><label for="incampus">Select Category</label>
  137. <input type="radio" name="campustype" value="in" onclick="toggleSelect('in');" /><label for="campustype">Music</label>
  138.  
  139. <input type="radio" name="campustype" value="off'" onclick="toggleSelect('off');" /><label for="campustype">Sports</label>
  140.  
  141. <input type="radio" name="campustype" value="1" onclick="toggleSelect('1');" /><label for="campustype">Art</label>
  142.  
  143. </p>
  144.  
  145.  
  146. <p<?php if (!empty($arrErrors['Name()'])) echo ' class="formerro"'; ?>>
  147.  
  148.     <?php if (!empty($arrErrors['Name()'])) echo '<br /><span class="errortext">'.$arrErrors['Name()'].'</span>'; ?><br/>
  149.  
  150. <select id="in-campu" name="howt">
  151.  <option name="hot"  value ="">--Select  Music Type--</option>
  152. <option name="how" value="tuiy">Concerts</option>
  153. <option name="hot" value="tfyrty" >Clubs</option>
  154. <option name="hot" value="rtyyt">Festival</option>
  155. <option name="hot" value="uyity">Opera</option>
  156.  
  157. </select>
  158.  
  159.  
  160.     <select id="off-campus" class="item" name="hot" style="display: none;">
  161.  <option name="dg" value=""> -- Select Sport Type -- </option>
  162. <option name="hot" value="dfg">Formula 1</option>
  163. <option name="hot" value="dfrg">Footbal</option>
  164. <option name="hot" value="dfgf">Basketball</option>
  165. <option name="how" value="rugby">Rugby</option>
  166. <option name="hot" value="cricket">Cricket</option>
  167. </select>
  168.  
  169.     <select id="1" class="item" name="ho" style="display: none;">
  170. <option name="hot" value=""> -- Select Art & Theatre Type -- </option>
  171. <option name="ht" value="hjk">Comedy</option>
  172. <option name="ho"  value=" gfhftgh">Drama</option>
  173. <option name="hghjot" value="ioiui">Museus</option>
  174. </select>
  175.  
  176. </p>
  177.  
  178.  
  179. <p>
  180.     <input type="submit" name="Submit" value="Submit">
  181. </p>
  182. </form>
  183. </body>
  184. </html>  
Apr 13 '10 #1
9 1690
how are represented A,B and C? where do you get them?
Apr 13 '10 #2
lisa007
29
sorry A B C meant to be howt, hot and ho those are the names of the drop dwon list if you look at the drop down list
Apr 13 '10 #3
what values do you want to give to A B and C?
also what are you trying to do with the function Name() ?
Apr 13 '10 #4
lisa007
29
if look at this array

Expand|Select|Wrap|Line Numbers
  1. if ($_POST['campustype']=='')
  2.         $arrErrors['campustype'] = 'Please select category.';
  3.  
  4.         which is then called
  5.  
  6. <p<?php if (!empty($arrErrors['campustype'])) echo ' class="formerro"'; ?>>
  7.  
  8.     <?php if (!empty($arrErrors['campustype'])) echo '<br /><span class="errortext">'.$arrErrors['campustype'].'</span>'; ?><br/><label for="incampus">Select Category</label>
  9. <input type="radio" name="campustype" value="in" onclick="toggleSelect('in');" /><label for="campustype">Music</label>
  10.  
  11. <input type="radio" name="campustype" value="off'" onclick="toggleSelect('off');" /><label for="campustype">Sports</label>
  12.  
  13. <input type="radio" name="campustype" value="1" onclick="toggleSelect('1');" /><label for="campustype">Art</label>
  14.  
  15. </p>
now i want to do the same with the drop down but if if all 3 drop downs have the same name the user will have to select the drop down 3 times in order to pass
is the original work i had

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Create an empty array to hold the error messages.
  3. $arrErrors = array();
  4. //Only validate if the Submit button was clicked.
  5. if (!empty($_POST['Submit'])) {
  6.     // Each time there's an error, add an error message to the error array
  7.     // using the field name as the key.
  8.     if ($_POST['name']=='')
  9.         $arrErrors['name'] = 'Please provide your name.';
  10.     if ($_POST['email']=='')
  11.         $arrErrors['email'] = 'A valid email address is required.';
  12.     if ($_POST['phone']=='')
  13.         $arrErrors['phone'] = 'Please provide your phone number.';
  14.  
  15.  
  16.         if ($_POST['campustype']=='')
  17.         $arrErrors['campustype'] = 'Please select category.';
  18.  
  19.  
  20.  
  21.  
  22.         if ($_POST['howt']=='')
  23.         $arrErrors['howt'] = 'select one field.';
  24.  
  25.  
  26.  
  27.  
  28.  
  29.     if (count($arrErrors) == 0) {
  30.         // If the error array is empty, there were no errors.
  31.         // Insert form processing here.
  32.     } else {
  33.         // The error array had something in it. There was an error.
  34.         // Start adding error text to an error string.
  35.         $strError = '<div class="formerror"><p><img src="/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again:</p><ul>';
  36.         // Get each error and add it to the error string
  37.         // as a list item.
  38.         foreach ($arrErrors as $error) {
  39.             $strError .= "<li>$error</li>";
  40.         }
  41.         $strError .= '</ul></div>';
  42.     }
  43. }
  44. ?>
  45.  
  46. <style>
  47.  
  48.  
  49. .formerror {
  50.   border: 1px solid red;
  51.   background-color : #FFCCCC;
  52.   width: auto;
  53.   padding: 5px 0;
  54. }
  55.  
  56. .errortext {
  57.   padding-left: 80px;
  58.   font-size:14px;
  59.   color:red;
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. </style>
  69.  
  70.  
  71. <script type="text/javascript">
  72. function toggleSelect(id)
  73. {
  74.     if (id == 'off')
  75.     {
  76.           document.getElementById('in-campu').style['display'] = 'none'; //ui
  77.           document.getElementById('1').style['display'] = 'none';
  78.           document.getElementById('off-campus').style['display'] = 'block';
  79.     }
  80.  
  81.     if (id == 'in')
  82.     {
  83.  
  84.           document.getElementById('off-campus').style['display'] = 'none';
  85.           document.getElementById('1').style['display'] = 'none';
  86.           document.getElementById('in-campu').style['display'] = 'block';//ui
  87.  
  88.     }
  89.  
  90. if (id == '1')
  91.     {
  92.           document.getElementById('off-campus').style['display'] = 'none';
  93.           document.getElementById('in-campu').style['display'] = 'none'; //ui
  94.           document.getElementById('1').style['display'] = 'block';
  95.     }
  96.  
  97. }
  98. </script>
  99.  
  100. <?php echo $strError; ?>
  101. <form method="post" action="<?php echo $PHP_SELF; ?>">
  102. <!--
  103. For every form field, we do the following...
  104.  
  105. Check to see if there's an error message for this form field. If there is,
  106. add the formerror class to the surrounding paragraph block. The formerror
  107. class contains the highlighted box.
  108.  
  109. Insert the contents of what the user submitted bak into the form field.
  110.  
  111. Check again to see if this field has an error message. If it does, show
  112. the error icon and the error message next to the field.
  113. -->
  114. <p<?php if (!empty($arrErrors['name'])) echo ' class="formerro"'; ?>>
  115.  
  116.     <?php if (!empty($arrErrors['name'])) echo '<br /><span class="errortext">'.$arrErrors['name'].'</span>'; ?>
  117. <br />
  118.     <label for="name">Name:</label>
  119.     <input name="name" type="text" id="name" value="<?php echo $_POST['name'] ?>">
  120. </p>
  121.  
  122.  
  123.  
  124. <p<?php if (!empty($arrErrors['campustype'])) echo ' class="formerro"'; ?>>
  125.  
  126.     <?php if (!empty($arrErrors['campustype'])) echo '<br /><span class="errortext">'.$arrErrors['campustype'].'</span>'; ?><br/><label for="incampus">Select Category</label>
  127. <input type="radio" name="campustype" value="in" onclick="toggleSelect('in');" /><label for="campustype">Music</label>
  128.  
  129. <input type="radio" name="campustype" value="off'" onclick="toggleSelect('off');" /><label for="campustype">Sports</label>
  130.  
  131. <input type="radio" name="campustype" value="1" onclick="toggleSelect('1');" /><label for="campustype">Art</label>
  132.  
  133. </p>
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. <p<?php if (!empty($arrErrors['howt'])) echo ' class="formerro"'; ?>>
  141.  
  142.     <?php if (!empty($arrErrors['howt'])) echo '<br /><span class="errortext">'.$arrErrors['howt'].'</span>'; ?><br/>
  143.  
  144. <select id="in-campu" name="howt">
  145.  <option name="hot"  value ="">--Select  Music Type--</option>
  146. <option name="how" value="tuiy">Concerts</option>
  147. <option name="hot" value="tfyrty" >Clubs</option>
  148. <option name="hot" value="rtyyt">Festival</option>
  149. <option name="hot" value="uyity">Opera</option>
  150.  
  151. </select>
  152.  
  153.  
  154.  
  155.  
  156.     <select id="off-campus" class="item" name="hot" style="display: none;">
  157.  <option name="dg" value=""> -- Select Sport Type -- </option>
  158. <option name="hot" value="dfg">Formula 1</option>
  159. <option name="hot" value="dfrg">Footbal</option>
  160. <option name="hot" value="dfgf">Basketball</option>
  161. <option name="how" value="rugby">Rugby</option>
  162. <option name="hot" value="cricket">Cricket</option>
  163. </select>
  164.  
  165.  
  166.  
  167.     <select id="1" class="item" name="ho" style="display: none;">
  168. <option name="hot" value=""> -- Select Art & Theatre Type -- </option>
  169. <option name="ht" value="hjk">Comedy</option>
  170. <option name="ho"  value=" gfhftgh">Drama</option>
  171. <option name="hghjot" value="ioiui">Museus</option>
  172. </select>
  173.  
  174.  
  175. </p>
  176.  
  177. <p<?php if (!empty($arrErrors['email'])) echo ' class="formerro"'; ?>>
  178.  
  179.     <?php if (!empty($arrErrors['email'])) echo '<br /><span class="errortext">'.$arrErrors['email'].'</span>'; ?>
  180. <br />
  181.     <label for="email">Email:</label>
  182.     <input name="email" type="text" id="email" value="<?php echo $_POST['email'] ?>">
  183. </p>
  184.  
  185.  
  186.  
  187. <p<?php if (!empty($arrErrors['phone'])) echo ' class="formerro"'; ?>>
  188.  
  189.     <?php if (!empty($arrErrors['phone'])) echo '<br /><span class="errortext">'.$arrErrors['phone'].'</span>'; ?>
  190. <br />
  191.     <label for="phone">Phone:</label>
  192.     <input name="phone" type="text" id="phone" value="<?php echo $_POST['phone'] ?>">
  193. </p>
  194.  
  195.  
  196.  
  197.  
  198. <p>
  199.     <input type="submit" name="Submit" value="Submit">
  200. </p>
  201. </form>
  202.  
Apr 13 '10 #5
i'm sorry i don't want you to loose your time nor i want to loose mine, your code is very very messy and I have no time to try to understand it, so please try to explain in words:
- what you have achieved so far,
- what you are trying to achieve //output
- what is the data that you have to treat to achieve what you want//input
Apr 13 '10 #6
lisa007
29
i have 3 drop dwon list as long the user select from one of the 3 drop down list pass the validation but if user doenst select from none of them display error message so the user is forced to select at at least form one drop down list and one only if none display error message
Apr 13 '10 #7
I will try to help and i hope im not mis answering.

lets say drop down lists are called 'a', 'b' and 'c':
first ensure at least one has something selected otherwise log an error message:

Expand|Select|Wrap|Line Numbers
  1. //first isolate the 3 drop downs
  2. $dDwns = array();
  3. $dDwns['a'] = $_POST['a'];
  4. $dDwns['b'] = $_POST['b'];
  5. $dDwns['c'] = $_POST['c'];
  6. //now perform the checks
  7. $filledDD = array(); //will contain filled drop downs
  8. foreach ($dDwns as $name => $value) {
  9.    //every not empty drop down will be rememebered
  10.    if ('' !== $value) {
  11.        $filledDD[$name] = $value;
  12.    }
  13. }
  14. //now ensure at least the minimum of dropDowns have been filled
  15. if (count($filledDD) === 0) {
  16.    $errorMessages['dropDown'] = 'You must at least fill one of the 3 drop downs';
  17.    $noContinueErrorCount++; //every time a "fatal" error is triggered increase count (fatal: the user can't go to next step)
  18. } else {
  19.    //do what you want with the data of the filled forms $filledDD
  20. }
  21.  
  22. //now present the data as you want
  23. if ($noContinueErrorCount > 0) {
  24.    //render the current form
  25.    formNumber1($validFields, $errorMessages);
  26. } else {
  27.    //render the next form
  28.    formNumber2();
  29. }
  30.  
Apr 13 '10 #8
lisa007
29
before you run away from me like evryone does i am trying to figure wher i should implement your code in my page in the meantime heres my options list if you can implement them before me i would much apreciate
i named them A B C i'm just learning php sorry about that


Expand|Select|Wrap|Line Numbers
  1. <select id="in-campu" name="A">
  2.  <option name="hot"  value ="">--Select  Music Type--</option>
  3. <option name="how" value="tuiy">Concerts</option>
  4. <option name="hot" value="tfyrty" >Clubs</option>
  5. <option name="hot" value="rtyyt">Festival</option>
  6. <option name="hot" value="uyity">Opera</option>
  7.  
  8. </select>
  9.  
  10.  
  11.     <select id="off-campus" class="item" name="B" style="display: none;">
  12.  <option name="dg" value=""> -- Select Sport Type -- </option>
  13. <option name="hot" value="dfg">Formula 1</option>
  14. <option name="hot" value="dfrg">Footbal</option>
  15. <option name="hot" value="dfgf">Basketball</option>
  16. <option name="how" value="rugby">Rugby</option>
  17. <option name="hot" value="cricket">Cricket</option>
  18. </select>
  19.  
  20.     <select id="1" class="item" name="C" style="display: none;">
  21. <option name="hot" value=""> -- Select Art & Theatre Type -- </option>
  22. <option name="ht" value="hjk">Comedy</option>
  23. <option name="ho"  value=" gfhftgh">Drama</option>
  24. <option name="hghjot" value="ioiui">Museus</option>
  25. </select>
  26.  
  27. </p>
Apr 13 '10 #9
@lisa007
i don't work for you, try to learn some php then come back when you have spotted questions. i wont code the site for you....
Apr 13 '10 #10

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

Similar topics

12
by: Mark Constant | last post by:
I have a drop-down list now and I got it so when something is selected from the drop down list it calls a JavaScript function. I want it so the value selected from the drop-down list is sent as a...
6
by: Kurt | last post by:
Hello. I am writing a C# program that uses CDO 1.21 to access the outlook addressbook as a contact management system The following code gives me the correct dialog box, but the "Show Names from...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
2
by: joltman | last post by:
OK, this is kind of hard to explain, so I'll do my best: I have a form where I have a row where there could be multiple entries, so I have a link where it will dynamically add another row like it,...
8
by: Randy Harris | last post by:
I've been working with Access for many years (early days of 2.0). Since leaving 2.0, one of my greatest frustrations with the product is the difficulty of locating procedures within a module. ...
1
by: Cesar | last post by:
Hello there, I'm facing the following situation: I have an aspx web page which contains several web controls (e.g button and drop down list). The drop down list in particular has enabled the...
17
by: DanielJohnson | last post by:
how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help.
12
by: ArunDhaJ | last post by:
Hi Friends, Is it possible to pass a table as a parameter to a funtion. whos function declaration would look some thing like this.... ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT) ...
14
by: adamjblakey | last post by:
Hi, I have a function here: var AdminResponse = ""; function parseResponse(){ var nText = AdminResponse.getElementsByTagName('optionText');
2
by: juliek | last post by:
I hope someone can help me. When a user selects a new item from a drop down list on an ASP.NET form, I'd like a javascript function to execute. How can I do this? I'm running the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.