Javascript/Ajax issue

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

Join Date: Sep 2008
Posts: 33
Reputation: jyotiu is an unknown quantity at this point 
Solved Threads: 0
jyotiu jyotiu is offline Offline
Light Poster

Javascript/Ajax issue

 
0
  #1
Jun 7th, 2009
Hi All,

Alright i am developing an application which is using ajax.

First of all there is a select box which is getting populated from db for a category ... now user can select one or more values from first select box ....

and there are four buttons for different categories ..... also i am using four buttons for selecting all, selecting one, removing one and removing all .....

once user selects an entry in select box and clicks the select button that value goes to the first div (using innerHtml) .....

now when user clicks on category second .... the first select box gets populated with values from db corresponding to the value in the first text box .... again user can select from these new values using select button ... which will go to the second div ..... and so on till the fourth category ....

all these values are being sent to next page for further calculations .......
i really don't know if its making any sense .... i hope it is ......

now everything is working fine except that since i am using a div
its not letting me deselect values ..... so i wanted that the values should go to corresponding select boxes instead of div's ......

here's the code for all the files .......

Please help me out ..... or even if someone can point in the right direction !!

page1.php
  1. <html>
  2. <head>
  3. <?php
  4. $host = "127.0.0.1";
  5. $user = "root";
  6. $pass = "";
  7.  
  8. $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
  9.  
  10. $dbname = "testview_flowview";
  11. mysql_select_db($dbname);
  12.  
  13. $id_facility=$_POST["id_facility"];
  14. $id_ValueSstream=$_POST["id_ValueSstream"];
  15. $id_Process=$_POST["id_Process"];
  16. $id_resource=$_POST["id_resource"];
  17. $endtime1=$_POST["endtime1"];
  18. $endtime2=$_POST["endtime2"];
  19. $entrydate1=$_POST["entrydate1"];
  20. $entrydate2=$_POST["entrydate2"];
  21. $starttime1=$_POST["starttime1"];
  22. $starttime2=$_POST["starttime2"];
  23. $graphplots=$_POST["checkbox1"];
  24. if (trim($graphplots)!="")
  25. {
  26. $graphplots1=$_POST["ddl_options" . trim($graphplots)];
  27. }
  28. $timeseries=$_POST["checkbox2"];
  29. ?>
  30.  
  31.  
  32. </head>
  33. <body id="mainbody">
  34. <center>
  35. <form name="form1" method="post" action="">
  36. <input type="hidden" name="processstep" value="1">
  37. <div id="div_Title">Test</div>
  38. <div id="maindiv">
  39. <div id="page1_listbox1_title" style="position:absolute;top:20px;left:50px;height:20px;width:100px;text-align:left;">Facility</div>
  40. <div style="position:absolute;top:45px;left:50px;width:100px;">
  41. <select name="listbox1" size="10" style="width:100px;" multiple="multiple">
  42. <?php
  43. $sql = "select * from facility";
  44. $query = mysql_query($sql);
  45.  
  46. while ($row = mysql_fetch_array($query))
  47. {
  48. echo "<option value='".$row['facility_id']."'>".$row['facility_name']."</option>";
  49. }
  50.  
  51. ?>
  52. </select>
  53. </div>
  54. <div style="position:absolute;top:45px;left:150px;width:100px;">
  55. <!--<input type=button name="selectall" value=" >> " style="width:50px;"><br>-->
  56. <input type="button" name="selectall" value=" >> " style="width:50px;" title="Select All" onClick="return onSelectallclick();"><br><br>
  57. <input type="button" name="selectone" value=" > " style="width:50px;" title="Select One" onClick="return onSelectclick();"><br><br>
  58. <input type="button" name="removeall" value=" << " style="width:50px;" title="Remove All" onClick="return onRemoveallclick();"><br>
  59. <!--<input type=button name="removeall" value=" << " style="width:50px;"><br>-->
  60. </div>
  61.  
  62. <script language="javascript" type="text/javascript">
  63. function onRemoveallclick()
  64. {
  65. if (form1.processstep.value=="1")
  66. {
  67. obj=document.getElementById("txt_Facility");
  68. obj.innerHTML="";
  69. form1.id_facility.value="";
  70. }
  71.  
  72. if (form1.processstep.value=="2")
  73. {
  74. obj=document.getElementById("txt_ValueStream");
  75. obj.innerHTML="";
  76. form1.id_ValueSstream.value="";
  77. }
  78. if (form1.processstep.value=="3")
  79. {
  80. obj=document.getElementById("txt_Process");
  81. obj.innerHTML="";
  82. form1.id_Process.value="";
  83. }
  84. if (form1.processstep.value=="4")
  85. {
  86. obj=document.getElementById("txt_Resource");
  87. obj.innerHTML="";
  88. form1.id_resource.value="";
  89. }
  90. }
  91.  
  92. function onSelectallclick()
  93. {
  94. var i;
  95. var s,s1;
  96. s="";
  97. s1="";
  98.  
  99. for (i=0;i<=form1.listbox1.options.length-1;i++)
  100. {
  101. if (s!="")
  102. s=s + ",";
  103. s=s+form1.listbox1.options[i].text;
  104.  
  105. if (s1!="")
  106. s1=s1 + ",";
  107. s1=s1+form1.listbox1.options[i].value;
  108. }
  109.  
  110. if (form1.processstep.value=="1")
  111. {
  112. obj=document.getElementById("txt_Facility");
  113. obj.innerHTML=s;
  114. form1.id_facility.value=s1;
  115. }
  116.  
  117. if (form1.processstep.value=="2")
  118. {
  119. obj=document.getElementById("txt_ValueStream");
  120. obj.innerHTML=s;
  121. form1.id_ValueSstream.value=s1;
  122. }
  123. if (form1.processstep.value=="3")
  124. {
  125. obj=document.getElementById("txt_Process");
  126. obj.innerHTML=s;
  127. form1.id_Process.value=s1;
  128. }
  129. if (form1.processstep.value=="4")
  130. {
  131. obj=document.getElementById("txt_Resource");
  132. obj.innerHTML=s;
  133. form1.id_resource.value=s1;
  134. }
  135. }
  136.  
  137. function onSelectclick()
  138. {
  139. var i;
  140. var s,s1;
  141. s="";
  142. s1="";
  143.  
  144. for (i=0;i<=form1.listbox1.options.length-1;i++)
  145. {
  146. if (form1.listbox1.options[i].selected)
  147. {
  148. if (s!="")
  149. s=s + ",";
  150. s=s+form1.listbox1.options[i].text;
  151.  
  152. if (s1!="")
  153. s1=s1 + ",";
  154. s1=s1+form1.listbox1.options[i].value;
  155. }
  156. }
  157.  
  158. if (form1.processstep.value=="1")
  159. {
  160. obj=document.getElementById("txt_Facility");
  161. obj.innerHTML=s;
  162. form1.id_facility.value=s1;
  163. }
  164. if (form1.processstep.value=="2")
  165. {
  166. obj=document.getElementById("txt_ValueStream");
  167. obj.innerHTML=s;
  168. form1.id_ValueSstream.value=s1;
  169. }
  170. if (form1.processstep.value=="3")
  171. {
  172. obj=document.getElementById("txt_Process");
  173. obj.innerHTML=s;
  174. form1.id_Process.value=s1;
  175. }
  176. if (form1.processstep.value=="4")
  177. {
  178. obj=document.getElementById("txt_Resource");
  179. obj.innerHTML=s;
  180. form1.id_resource.value=s1;
  181. }
  182.  
  183. }
  184.  
  185. function btnFacilityclick()
  186. {
  187. document.form1.processstep.value="1";
  188. var obj;
  189. obj=document.getElementById("page1_listbox1_title");
  190. obj.innerHTML="Facility";
  191. ajaxFunction("1");
  192. }
  193.  
  194. function btnValuestreamclick()
  195. {
  196. if (form1.id_facility.value=="")
  197. {
  198. alert("Please select facility");
  199. return false;
  200. }
  201. document.form1.processstep.value="2";
  202. var obj;
  203. obj=document.getElementById("page1_listbox1_title");
  204. obj.innerHTML="Value Stream";
  205. ajaxFunction("2");
  206. }
  207.  
  208. function btnProcessclick()
  209. {
  210. if (form1.id_ValueSstream.value=="")
  211. {
  212. alert("Please select Value stream");
  213. return false;
  214. }
  215. document.form1.processstep.value="3";
  216. var obj;
  217. obj=document.getElementById("page1_listbox1_title");
  218. obj.innerHTML="Process";
  219. ajaxFunction("3");
  220. }
  221.  
  222. function btnResourceclick()
  223. {
  224. if (form1.id_Process.value=="")
  225. {
  226. alert("Please select Process");
  227. return false;
  228. }
  229. document.form1.processstep.value="4";
  230. var obj;
  231. obj=document.getElementById("page1_listbox1_title");
  232. obj.innerHTML="Resource";
  233. ajaxFunction("4");
  234. }
  235. </script>
  236.  
  237. <?php
  238.  
  239. $name_facility="";
  240. if (trim($id_facility)!="")
  241. {
  242. $sql="select * from facility where facility_id in (" . $id_facility . ")";
  243. $query = mysql_query($sql);
  244. while ($row = mysql_fetch_array($query))
  245. {
  246. if (trim($name_facility)<>"")
  247. $name_facility=$name_facility . ";";
  248. $name_facility=$name_facility . $row['facility_name'] . " ";
  249. }
  250.  
  251. }
  252.  
  253. $name_ValueSstream="";
  254. if (trim($id_ValueSstream)!="")
  255. {
  256. $sql="select * from facility_stream where stream_id in (" . $id_ValueSstream . ")";
  257. $query = mysql_query($sql);
  258. while ($row = mysql_fetch_array($query))
  259. {
  260. if (trim($name_ValueSstream)<>"")
  261. $name_ValueSstream=$name_ValueSstream. ";";
  262. $name_ValueSstream=$name_ValueSstream . $row['stream_name'] . " ";
  263. }
  264. }
  265.  
  266. $name_Process="";
  267. if (trim($id_Process)!="")
  268. {
  269. $sql="select * from facility_process where process_id in (" . $id_Process . ")";
  270. $query = mysql_query($sql);
  271. while ($row = mysql_fetch_array($query))
  272. {
  273. if (trim($name_Process)<>"")
  274. $name_Process=$name_Process . ";";
  275. $name_Process=$name_Process . $row['process_name'] . " ";
  276. }
  277. }
  278.  
  279. $name_resource="";
  280. if (trim($id_resource)!="")
  281. {
  282. $sql="select * from facility_resource where resource_id in (" . $id_resource . ")";
  283. $query = mysql_query($sql);
  284. while ($row = mysql_fetch_array($query))
  285. {
  286. if (trim($name_resource)<>"")
  287. $name_resource=$name_resource . ";";
  288. $name_resource=$name_resource . $row['resource_name'] . " ";
  289. }
  290. }
  291.  
  292. ?>
  293. <div style="position:absolute;left:300px;top:45px;width:500px;height:50px;text-align:left;">
  294. <div>
  295. <input type="button" name="btn_facility" value="Facility" title="Click To Select Facility" style="position:ablolute;left:0px;top:0px;width:200px;height:50px;" onClick="return btnFacilityclick();">
  296. </div>
  297. <div id="txt_Facility" style="position:absolute;left:230px;top:0px;width:250px;height:50px;border:solid 1px #000000;">
  298. <?php echo $name_facility; ?></div>
  299. <input type="hidden" name="id_facility" value="<?php echo $id_facility; ?>">
  300. </div>
  301.  
  302. <div style="position:absolute;left:300px;top:100px;width:500px;height:50px;text-align:left;">
  303. <div>
  304. <input type="button" name="btn_ValueStream" value="Value Stream" title="Click To Select Value Stream" style="position:absolute;left:0px;top:0px;width:200px;height:50px;" onClick="return btnValuestreamclick();">
  305. </div>
  306. <div id="txt_ValueStream" style="position:absolute;left:230px;top:0px;width:250px;height:50px;border:solid 1px #000000;"><?php echo $name_ValueSstream; ?></div>
  307. <input name="id_ValueSstream" value="<?php echo $id_ValueSstream; ?>" type=hidden>
  308. </div>
  309.  
  310. <div style="position:absolute;left:300px;top:160px;width:500px;height:50px;text-align:left;">
  311. <div>
  312. <input type="button" name="btn_Process" value="Process" title="Click To Select Process" style="position:ablolute;left:0px;top:0px;width:200px;height:50px;" onClick="return btnProcessclick();">
  313. </div>
  314. <div id="txt_Process" style="position:absolute; width:250px;height:50px;border:solid 1px;top:0px;left:230px;"><?php echo $name_Process; ?></div>
  315. <input name="id_Process" value="<?php echo $id_Process; ?>" type="hidden">
  316. </div>
  317.  
  318. <div style="position:absolute;left:300px;top:220px;width:500px;height:50px;text-align:left;">
  319. <div>
  320. <input type="button" name="btn_Resource" value="Resource" title="Click To Select Resource" style="width:200px;height:50px;" onClick="return btnResourceclick();">
  321. </div>
  322. <div id="txt_Resource" style="position:absolute; width:250px;height:50px;border:solid 1px;top:0px;left:230px;" onClick="return btnResourceclick();"><?php echo $name_resource; ?></div>
  323. <input name="id_resource" value="<?php echo $id_resource; ?>" type="hidden">
  324. </div>
  325.  
  326. <div style="position:absolute;left:300px;top:350px;width:300px;height:30px;text-align:left;">
  327. <font size=2><strong>Start:</strong>&nbsp;&nbsp;</font>
  328. <script language="javascript">cal1.writeControl(); cal1.dateFormat="yyyy-MM-dd";</script>&nbsp;&nbsp;&nbsp;
  329. <input type="text" name="starttime1" size=2 value="<?php echo $starttime2; ?>" maxlength="2"><b>:</b><input type="text" name="starttime2" size=2 value="00" maxlength="2">
  330. </div>
  331. <div style="position:absolute;left:307px;top:380px;width:300px;height:30px;text-align:left;">
  332. <font size=2><strong>End:</strong>&nbsp;&nbsp;</font><script language="javascript">cal2.writeControl(); cal2.dateFormat="yyyy-MM-dd";</script>&nbsp;&nbsp;&nbsp;
  333. <input type="text" name="endtime1" size=2 value="<?php echo $endtime2; ?>" maxlength="2"><b>:</b><input type="text" name="endtime2" size=2 value="00" maxlength="2">
  334. </div>
  335.  
  336. <div style="position:absolute;left:300px;top:450px;width:200px;height:50px;border:solid 0px;">
  337. <input type="button" name="btn_option" value="Option" style="width:200px;height:50px;" onClick="return btnOptionClick();">
  338. </div>
  339. <div style="position:absolute;left:500px;top:450px;width:200px;height:50px;border:solid 0px;">
  340. <input type="button" name="btn_ok" value="Generate Report" style="width:200px;height:50px;" onClick="return btnOKClick();" <?php if ((trim($graphplots)=="") && (trim($timeseries)=="")) echo "disabled"; ?>>
  341. </div>
  342. <div style="position:absolute;left:500px;top:510px;width:200px;height:50px;border:solid 0px;">
  343. <input type="button" name="btn_cancel" value="Cancel" style="width:200px;height:50px;">
  344. </div>
  345. </div>
  346.  
  347. <script language="javascript" type="text/javascript">
  348. function btnOptionClick()
  349. {
  350. form1.action="page3.php";
  351. form1.submit();
  352. }
  353.  
  354. function btnOKClick()
  355. {
  356. if (form1.id_Process.value=="")
  357. {
  358. alert("Please select Process");
  359. return;
  360. }
  361. if (form1.entrydate1.value=="")
  362. {
  363. alert("Please select date");
  364. return;
  365. }
  366. if (form1.entrydate2.value=="")
  367. {
  368. alert("Please select data");
  369. return;
  370. }
  371.  
  372. form1.action="page2.php";
  373. form1.submit();
  374. }
  375.  
  376. function ajaxFunction(t)
  377. {
  378. var xmlHttp;
  379. try
  380. { // Firefox, Opera 8.0+, Safari
  381. xmlHttp=new XMLHttpRequest();
  382. }
  383. catch (e)
  384. { // Internet Explorer
  385. try
  386. {
  387. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  388. }
  389. catch (e)
  390. {
  391. try
  392. {
  393. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  394. }
  395. catch (e)
  396. {
  397. alert("Your browser does not support AJAX!");
  398. return false;
  399. }
  400. }
  401. }
  402.  
  403.  
  404. while (form1.listbox1.options.length>0)
  405. form1.listbox1.options[0]=null;
  406. var u;
  407. if(t=="1")
  408. u="getparams.php?mode=1";
  409. else if(t=="2")
  410. u="getparams.php?mode=2&param1="+form1.id_facility.value;
  411. else if(t=="3")
  412. u="getparams.php?mode=3&param1="+form1.id_ValueSstream.value;
  413. else if(t=="4")
  414. u="getparams.php?mode=4&param1="+form1.id_Process.value;
  415.  
  416.  
  417. if(u!="")
  418. {
  419. xmlHttp.open("GET",u,true);
  420.  
  421. }
  422.  
  423. xmlHttp.onreadystatechange=function()
  424. {
  425. //if(xmlHttp.readyState==4)
  426. var b=false
  427. try
  428. {
  429. if (xmlHttp.status==200)
  430. b=true;
  431. }
  432. catch(e)
  433. {
  434. try
  435. {
  436. if (xmlHttp.readyState==4)
  437. b=true
  438. }
  439. catch(e)
  440. {
  441.  
  442. }
  443. }
  444.  
  445. if (b==true)
  446. {
  447. var s;
  448. var arr=new Array();
  449. s=xmlHttp.responseText;
  450.  
  451. //s=s.replace(/^\s+|\s+$/g, '') ;
  452.  
  453. if (s=="") return;
  454.  
  455.  
  456. arr=s.split("|");
  457.  
  458. while (form1.listbox1.options.length>0)
  459. form1.listbox1.options[0]=null;
  460.  
  461. j=0;
  462. for (i=arr.length-2;i>=0;i--)
  463. {
  464. s=arr[i];
  465. arr1=s.split("-");
  466. o=new Option(arr1[1],arr1[0]);
  467. form1.listbox1.options[j]=o;
  468. j++;
  469. }
  470. }
  471. }
  472.  
  473. xmlHttp.send(null);
  474. }
  475.  
  476. </script>
  477.  
  478. </form>
  479. </center>
  480. </body>
  481. </html>


getparams.php :::

  1. <?php
  2. $host = "127.0.0.1";
  3. $user = "root";
  4. $pass = "";
  5.  
  6.  
  7. $connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
  8.  
  9. $dbname = "testview_flowview";
  10. mysql_select_db($dbname);
  11.  
  12. $mode=$_GET["mode"];
  13. $param1=$_GET["param1"];
  14.  
  15. if ($mode=="1")
  16. {
  17. $sql = "select * from facility";
  18. $query = mysql_query($sql);
  19.  
  20. while ($row = mysql_fetch_array($query))
  21. {
  22. echo $row['facility_id']."-".$row['facility_name']."|";
  23. }
  24.  
  25. }
  26.  
  27. if (($mode=="2") && ($param1 !=""))
  28. {
  29. $sql = "select * from facility_stream where facility_id in (" . $param1 . ") ";
  30. $query = mysql_query($sql);
  31.  
  32. while ($row = mysql_fetch_array($query))
  33. {
  34. echo $row['stream_id']."-".$row['stream_name']."|";
  35. }
  36.  
  37. }
  38.  
  39. if (($mode=="3") && ($param1 !=""))
  40. {
  41. $sql = "select a.* from facility_process a left join facility_stream_process b on (a.process_id=b.process_id) where b.stream_id in (" . $param1 . ") ";
  42. $query = mysql_query($sql);
  43.  
  44. while ($row = mysql_fetch_array($query))
  45. {
  46. echo $row['process_id']."-".$row['process_name']."|";
  47. }
  48.  
  49. }
  50.  
  51. if (($mode=="4") && ($param1 !=""))
  52. {
  53. $sql = "select distinct a.resource_id,c.resource_name from facility_stream_process_resource a left join facility_stream_process b on (a.stream_process_id =b.stream_process_id ) left join facility_resource c on (c.resource_id =a.resource_id) where b.process_id in (" . $param1 . ") ";
  54.  
  55. $query = mysql_query($sql);
  56.  
  57. while ($row = mysql_fetch_array($query))
  58. {
  59. echo $row['resource_id']."-".$row['resource_name']."|";
  60. }
  61.  
  62. }
  63. ?>

Please help me out !!! As Always ..... Thanks a million in advance !!

Warm Regards,
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: Javascript/Ajax issue

 
0
  #2
Jun 10th, 2009
Try this demo:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  2. <?xml-stylesheet type="text/css" href="#ccs21" media="all"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  4. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  5. <html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6. <head profile="http://www.w3.org/2005/10/profile">
  7. <!--[if IE]>
  8. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  9. <![endif]-->
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  11. <meta http-equiv="Content-Style-Type" content="text/css" />
  12. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  13. <title>Free Live Help!</title>
  14. <style id="css21" type="text/css" media="all">
  15. /* <![CDATA[ */
  16.  
  17. div#main {
  18. clear : both;
  19. letter-spacing : 1px;
  20. margin : 0 auto;
  21. width : auto;
  22. vertical-align : baseline; }
  23.  
  24. select {
  25. display : block;
  26. margin : 0 auto;
  27. width : 100%; }
  28.  
  29. caption {
  30. color : #778899;
  31. margin-bottom : 1%;
  32. text-align : left; }
  33.  
  34. table {
  35. border : none;
  36. border-collapse : collapse; }
  37.  
  38. th {
  39. background-color : #fff;
  40. vertical-align : middle;
  41. border-top : 1px solid #ddd;
  42. border-bottom : 1px solid #ddd;
  43. border-right : 1px solid #ddd;
  44. font-weight : normal;
  45. width : 30%; }
  46.  
  47. td {
  48. border : 1px solid #ddd;
  49. background-color : #fff;
  50. width : auto;
  51. padding : 1% 0 1% 0; }
  52.  
  53. div.tube {
  54. background-color : #FFF;
  55. color : #888;
  56. padding : 2%; }
  57.  
  58. div#show {
  59. margin-top : 1em; }
  60. .show { display : block; }
  61. .hide { display : none; }
  62. /* ]]> */
  63. </style>
  64. <script id="script15" type="text/javascript">
  65. // <![CDATA[
  66.  
  67. var handleRequest = function( ids, index ) {
  68. div = (( document.getElementById ) ? document.getElementById("show") : document.all.show );
  69. sel = (( document.getElementById ) ? document.getElementById("cats1") : document.all.cats1 );
  70.  
  71. response = xmlHttp.responseText;
  72. if (( xmlHttp.readyState === 4 ) || ( xmlHttp.readyState === "complete" )) {
  73. // if ( xmlHttp.status === 200 ) {
  74. div.className = div.id; sel.remove( index );
  75. sel.add( new Option( ids.options[ index ].text, index ), index ); sel.options[index].selected = true;
  76. // }
  77. }
  78. };
  79. var update = function() {
  80. (( sel.options.length === 1 ) ? div.className = "hide" : div );
  81. sel.remove( sel.selectedIndex );
  82.  
  83. }
  84.  
  85. var sendRequest = function( ids ) {
  86. ids = (( document.getElementById ) ? document.getElementById( ids ) : document.all[ ids ] );
  87. index = ids.selectedIndex;
  88. url = ids.options[ index ].value;
  89. xmlHttp = null;
  90. method = "GET";
  91. try {
  92. if ( window.XMLHttpRequest ) {
  93. xmlHttp = new XMLHttpRequest();
  94. } else if ( window.ActiveXObject ) {
  95. try {
  96. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  97. } catch( e1 ) {
  98. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  99. }
  100. }
  101. } catch( e2 ) {
  102. (( window.createRequest ) ? xmlHttp = window.createRequest() : xmlHttp = null );
  103. }
  104. (( xmlHttp.overrideMimeType ) ? xmlHttp.overrideMimeType("text/xml") : xmlHttp );
  105. if ( xmlHttp !== null ) {
  106. xmlHttp.onreadystatechange = function() {
  107. handleRequest( ids, index );
  108. }; xmlHttp.open( method, "test.txt", true );
  109. (( xmlHttp.setRequestHeader && method === "POST" ) ? xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") : xmlHttp );
  110. xmlHttp.send( null );
  111. } else {
  112. alert("\nYour browser does not support AJAX Request!");
  113. }
  114. };
  115.  
  116.  
  117. // ]]>
  118. </script>
  119. </head>
  120. <body>
  121. <div id="main">
  122. <div class="tube">
  123. <form id="testform" action="#" onsubmit="return false;">
  124. <table width="100%" id="testtable" frame="void" rules="none" summary="AJAX Powered Demo">
  125. <caption>Product Line:</caption>
  126. <tr>
  127. <th><label for="cats">Performance Upgrade</label></th>
  128. <td><select id="cats" name="cats" size="4" onchange="sendRequest( this.id, this.selectedIndex );">
  129. <optgroup label=" - Product Brands - ">
  130. <option value="./hks.txt">HKS High-Performance Parts</option>
  131. <option value="greddy">GREDDY Intercooler Kits</option>
  132. <option value="brembo">Brembo Braking System</option>
  133. </optgroup>
  134. </select>
  135. <div id="show" class="hide">
  136. <p style="padding-left : 1em;">Here are the following lists of items selected from the brand categories.<br />
  137. Click items to deselect.</p>
  138.  
  139. <select id="cats1" name="cats1" size="4" multiple="multiple" onchange="update();">
  140. <option value="">No Parts Selected</option>
  141. </select></div>
  142. </td>
  143. </tr>
  144. </table>
  145. </form>
  146. </div>
  147. </div>
  148. </body>
  149. </html>

- you must replace the ajax path, to your own text file...
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC