Simple Java Script Question

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Simple Java Script Question

 
0
  #1
Sep 13th, 2008
Hi guys,

I am trying to hide 2 list boxes, then on selection changed show a new list box with JavaScript, i am very very new to web development in general, I am actually a software developer in the Pascal and C# language so this is all very new to me, please help with any ideas or code ?

This is what i have

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%">
  3.  
  4. <tr>
  5. <td align="center" valign="middle" style="background: url('Image2.jpg') no-repeat fixed 50% top; height: 113px; color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant: normal; font-weight: bold; line-height: normal;" valign="top" class="style1">
  6. NCS Quote System</td>
  7. </tr>
  8.  
  9. <tr >
  10. <td style="width: 100%" valign="top" align="center" >
  11.  
  12. <select title="Select a section :">
  13.  
  14. <?php
  15. //Selecting table Sections *****************************************************************
  16. $Sections = mysql_query("SELECT * FROM sections", $connection);
  17.  
  18. if (!$Sections)
  19. {
  20. die("Database query failed : " .mysql_error() );
  21. }
  22.  
  23. while ($RowSections = mysql_fetch_array($Sections))
  24. {
  25. echo '<option value='.$RowSections['Description'].'>'.$RowSections['Description'].'</option>';
  26. }
  27.  
  28. echo '</select>';
  29. ?>
  30.  
  31. </td>
  32.  
  33. </tr>
  34.  
  35. <tr>
  36. <td style="width: 100%" valign="top" align="center">
  37. <?php
  38.  
  39. echo '<select>';
  40.  
  41. //Selecting table Categories *********************************************************
  42. $Categories = mysql_query("SELECT * FROM categories, section_category_link WHERE categories.id = section_category_link.CategoryId", $connection);
  43.  
  44. if (!$Categories)
  45. {
  46. die("Database query failed : " .mysql_error() );
  47. }
  48.  
  49. while ($RowCategories = mysql_fetch_array($Categories))
  50. {
  51. echo '<option value='.$RowCategories['Description'].'>'.$RowCategories['Description'].'</option>';
  52. }
  53. echo '</select>';
  54. ?>
  55.  
  56.  
  57.  
  58. </td>
  59. </tr>
  60.  
  61. <tr>
  62. <td style="width: 20%" valign="top" align="center">
  63. <?php
  64.  
  65. echo '<select>';
  66.  
  67. //Selecting table Sub_Categories ******************************************************************
  68. $Sub_Categories = mysql_query("SELECT * FROM subcategories, category_subcategory_link WHERE subcategories.id = category_subcategory_link.CategoryId ", $connection);
  69.  
  70. if (!$Sub_Categories)
  71. {
  72. die("Database query failed : " .mysql_error() );
  73. }
  74.  
  75. while ($RowSubCategories = mysql_fetch_array($Sub_Categories))
  76. {
  77. echo '<option value='.$RowSubCategories['Description'].'>'.$RowSubCategories['Description'].'</option>';
  78. }
  79. echo '</select>';
  80. ?>
  81.  
  82.  
  83. </td>
  84. </tr>
  85.  
  86. <tr>
  87. <td style="width: 20%" valign="top" align="center">
  88. <?php
  89.  
  90. //Selecting table Sub_Categories ********************************************************************
  91. $Items = mysql_query("SELECT * FROM items, subcategory_item_link WHERE items.Id = subcategory_item_link.ItemId", $connection);
  92.  
  93. if (!$Items)
  94. {
  95. die("Database query failed : " .mysql_error() );
  96. }
  97.  
  98. while ($RowItems = mysql_fetch_array($Items))
  99. {
  100. echo $RowItems["FullDescription"]. ", " .$RowItems["ShortDescription"] . ", " .$RowItems[""] . "<br />";
  101. }
  102. ?>
  103.  
  104.  
  105. </td>
  106. </tr>
  107. </table>

I am aware of the fact that there is no Java Script in there yet because i have no idea how to go about this ...

Any help would be appreciated

Yours sincerely

Paul
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Simple Java Script Question

 
0
  #2
Sep 14th, 2008
Hope this example will help you on your way in learning javascript!
And Good day to you!


  1. <html>
  2. <head>
  3. <title><!--Sample--></title>
  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3.  
  4. /* ADD
  5.  OPTION TO YOUR SELECTION LIST */
  6. function addOpt()
  7. { /* You can also use the
  8.   addOption function
  9.   instead of this one!
  10.   But since my browser
  11.   doesnt support it!
  12.   Then ill have to use the
  13.   createElement method
  14.   to add option on the list!
  15.   */
  16.  
  17. var select = document.getElementsByTagName('select')[0];
  18. var option = document.createElement('option');
  19. for ( var x = 0; x < form1.list.options.length; x++ )
  20. { option.text = 'Selection List ' + x; }
  21. select.appendChild(option);
  22. }
  23.  
  24. <!-- SHOW AND HIDE YOUR COMBOboX! -->
  25. function hideMe( thisItem )
  26. {
  27. div = document.getElementsByTagName('div');
  28. div[thisItem].style.visibility = "hidden";
  29. div['control'].innerText = 'Show Me!';
  30. div['control'].onclick = function() { div['control'].innerText = "Hide Me!"; div['control'].onclick = "hideMe(\"sample\");"; div[thisItem].style.visibility = "visible"; }
  31. }
  32. // AND I'M DONE WITH HIDING -->
  33. </script>
  1. </head>
  2. <body>
  3. <div id="sample">
  4. <form name="form1" action="#" onsubmit="return false;">
  5. <select name="list" onchange="addOpt();">
  6. <option>Hide Me!</option>
  7. <option>Add</option>
  8.  
  9. </select>
  10. </form>
  11. </div>
  12. <div id="control" onclick="hideMe('sample');">Hide Me!</div>
  13. </body>
  14. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 213
Reputation: nikesh.yadav is an unknown quantity at this point 
Solved Threads: 17
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Posting Whiz in Training

Re: Simple Java Script Question

 
0
  #3
Sep 18th, 2008
done
Help as an alias

I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC