473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Get value from javascript to PHP

20
Hi,

I am writing a PHP script to get a ping reply from my LAN PC. So, my idea is like this, when i mouseover/mouse click to the "hostname" display on the web. There will be a hint box appear and show me the ping result. Below is the php function to perform exec:

Expand|Select|Wrap|Line Numbers
  1. function getdetail($user1)
  2. {
  3. $auser=$user1;
  4. exec("ping $auser", $coutput);
  5. foreach ($coutput as $line) {
  6. echo $line."<br />";
  7.              }
  8. }
  9.  
Below is the hint box javascript from dynamicdrive.com:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. /***********************************************
  4. * Show Hint script- ? Dynamic Drive (www.dynamicdrive.com)
  5. * This notice MUST stay intact for legal use
  6. * Visit http://www.dynamicdrive.com/ for this script and 100s more.
  7. ***********************************************/
  8.  
  9. var horizontal_offset="9px" //horizontal offset of hint box from anchor link
  10.  
  11. /////No further editting needed
  12.  
  13. var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
  14. var ie=document.all
  15. var ns6=document.getElementById&&!document.all
  16.  
  17. function getposOffset(what, offsettype){
  18. var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  19. var parentEl=what.offsetParent;
  20. while (parentEl!=null){
  21. totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
  22. parentEl=parentEl.offsetParent;
  23. }
  24. return totaloffset;
  25. }
  26.  
  27. function iecompattest(){
  28. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  29. }
  30.  
  31. function clearbrowseredge(obj, whichedge){
  32. var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
  33. if (whichedge=="rightedge"){
  34. var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
  35. dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
  36. if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
  37. edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
  38. }
  39. else{
  40. var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
  41. dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
  42. if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
  43. edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
  44. }
  45. return edgeoffset
  46. }
  47.  
  48. function showhint(menucontents, obj, e, tipwidth){
  49. if ((ie||ns6) && document.getElementById("hintbox")){
  50. dropmenuobj=document.getElementById("hintbox")
  51. dropmenuobj.innerHTML=menucontents
  52. dropmenuobj.style.left=dropmenuobj.style.top=-500
  53. if (tipwidth!=""){
  54. dropmenuobj.widthobj=dropmenuobj.style
  55. dropmenuobj.widthobj.width=tipwidth
  56. }
  57. dropmenuobj.x=getposOffset(obj, "left")
  58. dropmenuobj.y=getposOffset(obj, "top")
  59. dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
  60. dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
  61. dropmenuobj.style.visibility="visible"
  62. obj.onmouseout=hidetip
  63. }
  64. }
  65.  
  66. function hidetip(e){
  67. dropmenuobj.style.visibility="hidden"
  68. dropmenuobj.style.left="-500px"
  69. }
  70.  
  71. function createhintbox(){
  72. var divblock=document.createElement("div")
  73. divblock.setAttribute("id", "hintbox")
  74. document.body.appendChild(divblock)
  75. }
  76.  
  77. if (window.addEventListener)
  78. window.addEventListener("load", createhintbox, false)
  79. else if (window.attachEvent)
  80. window.attachEvent("onload", createhintbox)
  81. else if (document.getElementById)
  82. window.onload=createhintbox
  83.  
  84. /* get id from <a> */
  85. function getValue()
  86. {
  87. var x=document.getElementById("computer1").id
  88. document.write(x)
  89. }
  90. </script>
  91.  
finally, the host display:
Expand|Select|Wrap|Line Numbers
  1. <a href="#"  id="computer1" onclick="showhint('<? getdetail(?>getValue()<?); ?>', this, event, '200px')">tiwlim</a>
  2.  
May i know why the final code above is not working? How do i get value from javascript -> php?

Thanks!
Nov 26 '07 #1
1 2800
pbmods
5,821 Expert 4TB
Heya, Danny.

My guess is that the ping command on the server side is sending an unlimited number of pings. Since the exec() command doesn't return anything until the command is finished, it never returns.

Try using the -c parameter for ping to limit the number of pings sent. `man ping` for more information.
Nov 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: NewbieJon | last post by:
I am attempting to send the variable "sComputerName" from my ActiveX script to "GetInfo.asp" using javascript. (Having been advised this is the way to get my ActiveX variable into my ASP script) ...
16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
7
by: ???????J | last post by:
Javascript may inquire the push down menu value, can I inquire the description? The following example, the variable($answer) can be get the menu1's value. For example, if I select first data,...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
6
by: Guadala Harry | last post by:
I have some client-side JavaScript that, among other things, calculates the value of a variable (myVar). On the server I have a stored procedure that needs to somehow receive as an input parameter...
1
by: platostoteles | last post by:
Hallo NG, I am new to JavaScript and would really appreciate any help to solve my problem. I am using the blow code in my form to validate form fields. What I would like to accomplish is that...
5
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that...
7
by: ravi | last post by:
Hi, I am a newbie to javascript. Iam working on a page that has two radio buttons and a tree. I do not have my tree nodes to be selectable. Iam working on Firefox. I have the firebug...
3
by: zac540 | last post by:
Hey everyone! First of all I'd like to say that I did my best to look for any other relevant posts. The best I found was this interesting thread.. http://bytes.com/forum/thread594982.html If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.