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

Join Date: Oct 2009
Posts: 5
Reputation: jyotidagia is an unknown quantity at this point 
Solved Threads: 0
jyotidagia jyotidagia is offline Offline
Newbie Poster

javascript php

 
0
  #1
32 Days Ago
hey all..
i was wondering if anyone culd help me wid this..

i've a html file with javascript and a php file..
i need to access the db result generated by the php file in my javascript..to dynamically load drop down menu in the html file..

was wondering if i cud use somehin like..

var abc='load.php?array_name='+array_name;
to access the array in php file..

thanks in advance..:-)
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: alagirinetaxis is an unknown quantity at this point 
Solved Threads: 3
alagirinetaxis alagirinetaxis is offline Offline
Newbie Poster
 
0
  #2
32 Days Ago
Send File Code and Details

AJAX is usefull for this concept
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 525
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 61
network18 network18 is offline Offline
Posting Pro
 
0
  #3
30 Days Ago
on click of the select element run the php file through ajax which will fetch the values from the db and will populate the select element.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 5
Reputation: jyotidagia is an unknown quantity at this point 
Solved Threads: 0
jyotidagia jyotidagia is offline Offline
Newbie Poster
 
0
  #4
29 Days Ago
Originally Posted by network18 View Post
on click of the select element run the php file through ajax which will fetch the values from the db and will populate the select element.
it would be gr8 if you could help with the code snippets..coz m fairly new to php and ajax..

do you mean something like..
<select name=blabla onclick=function_name_inajax();>

thanks in adavance..
do not forget to send sample code..
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 525
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 61
network18 network18 is offline Offline
Posting Pro
 
0
  #5
25 Days Ago
It will be good if you try to code yourself, we are always there to help you out if you get stuck up somewhere in the code, to start with, here is the ajax functions you can use -
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function httpRespObj(url)
  2. {
  3. try
  4. {
  5. xmlHttp=new XMLHttpRequest();
  6. }
  7. catch (e)
  8. {
  9. try
  10. {
  11. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  12. }
  13. catch (e)
  14. {
  15. try
  16. {
  17. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  18. }
  19. catch (e)
  20. {
  21. alert("Your browser does not support AJAX!");
  22. return false;
  23. }
  24. }
  25. }
  26.  
  27. xmlHttp.open("GET",url,false);
  28. xmlHttp.onreadystatechange=responseBack;
  29. xmlHttp.send(null);
  30. }
  31.  
  32. function responseBack()
  33. {
  34. if(xmlHttp.readyState==4)
  35. {
  36. //put the response to the html select element
  37. document.getElementById("selElement").value = xmlHttp.responseText;
  38. }
  39. else
  40. {
  41. document.getElementById("selElement").value="";
  42. }
  43. }
you can call the httpRespObj(url) on focus of the select element(whatever way you like it).
"url" is your php script (i called it fetch.php) which fetches the data from the db.
<select onFocus="return httpRespObj('fetch.php?id=<?=$id?>');">
If you dont need to pass any id to the request, you can safely omit that part
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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