944,028 Members | Top Members by Rank

Ad:
Oct 27th, 2009
0

javascript php

Expand Post »
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..:-)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jyotidagia is offline Offline
5 posts
since Oct 2009
Oct 27th, 2009
0
Re: javascript php
Send File Code and Details

AJAX is usefull for this concept
Reputation Points: 10
Solved Threads: 3
Newbie Poster
alagirinetaxis is offline Offline
15 posts
since Oct 2009
Oct 29th, 2009
0
Re: javascript php
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.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Oct 30th, 2009
0
Re: javascript php
Click to Expand / Collapse  Quote originally posted by network18 ...
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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jyotidagia is offline Offline
5 posts
since Oct 2009
Nov 3rd, 2009
0
Re: javascript php
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
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Dynamic Ajax Content and Jquery
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: New web design need help connecting sql database to display content in a form mask





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC