Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 3.41 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Help with ajax scripts
  2. // Initialize the object:
  3. var ajax = false;
  4.  
  5. // Create the object...
  6.  
  7. // Choose object type based upon what's supported:
  8. if (window.XMLHttpRequest) {
  9.  
  10.     // IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
  11.     ajax = new XMLHttpRequest();
  12.  
  13. } else if (window.ActiveXObject) { // Older IE browsers
  14.  
  15.     // Create type Msxml2.XMLHTTP, if possible:
  16.     try {
  17.         ajax = new ActiveXObject("Msxml2.XMLHTTP");
  18.     } catch (e1) { // Create the older type instead:
  19.         try {
  20.             ajax = new ActiveXObject("Microsoft.XMLHTTP");
  21.         } catch (e2) { }
  22.     }
  23.  
  24. }
  25.  
  26. // Send an alert if the object wasn't created.
  27. if (!ajax) {
  28.     alert ('Page functionality is unavailable.');
  29. }
  30.  
  31. // Function that starts the Ajax process:
  32. function categories_chain(username) {
  33.  
  34.     // Confirm that the object is usable:
  35.     if (ajax) {
  36.  
  37.         // Call the PHP script.
  38.         // Use the GET method.
  39.         // Pass the username in the URL.
  40.         ajax.open('get', 'categories.php?' + encodeURIComponent(username));
  41.  
  42.         // Function that handles the response:
  43.         ajax.onreadystatechange = handle_check;
  44.  
  45.         // Send the request:
  46.         ajax.send(null);
  47.  
  48.  
  49. } // End of check_username() function.
  50.  
  51. // Function that handles the response from the PHP script:
  52. function handle_check() {
  53.  
  54.     // If everything's OK:
  55.     if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
  56.  
  57.         // Assign the returned value to a document element:
  58.         document.getElementById('cat2').innerHTML = ajax.responseText;
  59.  
  60.     }
  61.  
  62. } // End of handle_check() function.
  63.        
  64. <?php
  65. if(isset($_GET['1'])) {
  66.     echo <<<HERE_DOC
  67. <option value="1.1">Antiquities ></option>
  68. <option value="1.2">Architectural & Garden ></option>
  69. <option value="1.3">Asian Antiques ></option>
  70. <option value="1.4">Books & Manuscripts ></option>
  71. <option value="1.5">Decorative Arts ></option>
  72. <option value="1.6">Ethnographic ></option>
  73. <option value="1.7">Furniture ></option>
  74. <option value="1.8">Home & Hearth ></option>
  75. <option value="1.9">Linens & Textiles (Pre-1930) ></option>
  76. <option value="1.10">Maps, Atlases & Globes ></option>
  77. <option value="1.11">Maritime ></option>
  78. <option value="1.12">Mercantile, Trades & Factories ></option>
  79. <option value="1.13">Musical Instruments (Pre-1930) ></option>
  80. <option value="1.14">Periods & Styles ></option>
  81. <option value="1.15">Primitives</option>
  82. <option value="1.16">Restoration & Care ></option>
  83. <option value="1.17">Rugs & Carpets ></option>
  84. <option value="1.18">Science & Medicine (Pre-1930) ></option>
  85. <option value="1.19">Sewing (Pre-1930) ></option>
  86. <option value="1.20">Silver ></option>
  87. <option value="1.21">Reproduction Antiques</option>
  88. <option value="1.22">Other</option>
  89. HERE_DOC;
  90. }
  91.  
  92. if(isset($_GET['2'])) {
  93.     echo <<<HERE_DOC
  94. <option value="60435">Direct from the Artist ></option>
  95. <option value="158658">Art from Dealers & Resellers ></option>
  96. <option value="52524">Wholesale Lots ></option>
  97. HERE_DOC;
  98. }
  99. ?>
  100.        
  101. <!DOCTYPE HTML>
  102. <html>
  103. <head>
  104.     <script src="categories.js" type="text/javascript" language="javascript">                                           </script>
  105. </head>
  106. <body>
  107. <form name="postadd">
  108.     <div id='div1'>
  109.         <select name="cat1"     onChange='categories_chain(cat1.options[selectedIndex].value)'>
  110.             <option value="1">Antiques ></option>
  111.             <option value="2">Art ></option>
  112.             <option value="3">Automotive ></option>
  113.         </select>
  114.     </div>
  115.     <div id='div2'>
  116.     </div>
  117. </body>
  118. </html>