Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better Way of Writing to a Field 1

Status
Not open for further replies.

Signit

MIS
Oct 17, 2003
114
US
I am working with a combination of ColdFusion and JavaScript to perform a ping for a customer requested app (tried to disuade them from this, but they were adamant). Presently I am performing the ping by creating a list of ip addresses to ping and providing the customer with a checkbox next to each ip. As a customer clicks on the checkboxes I am firing off a seperate window which is running some ColdFusion and JavaScript to perform the ping. This seperate window then returns the status of those variables to a function that writes a value to a disabled textbox on the page. I am wondering if there is a cleaner way of doing this, specifically when writing out to the disabled textbox. I'd like to write the text directly to the HTML page if there is a way of doing so. I've put examples of my code below (somethings are hardcoded for ease of viewing).

main page
Code:
<html>
<cfoutput>
  <script language="javascript">
    function checkbox_checked(checkbox_key,ipAddress)
    {
      if (document.#FormName#.ip[checkbox_key].checked)
        ping(checkbox_key,ipAddress);
      else
        document.#FormName#.pingableText[checkbox_key].value = "";
    }
    
    function ping(checkbox_key,ipAddress)
    {
      pingWindow = window.open("","pingWindow","status=yes,resizeable=no,scrollbars=no,width=1,height=1");
      pingWindow.focus();
      pingWindow.creator = self;
      pingWindow.location.href = "#templatepath#/ping.cfm?checkbox_key=" + checkbox_key + "&ipaddress=" + ipAddress;
      return;
    }
    
    function set_pingable(checkbox_key,pingable)
    {
      document.#FormName#.pingableText[checkbox_key].value = pingable;
    }
  </script>
<body bgcolor=cornsilk>
<form name="#FormName#">
</cfoutput>
  <table border="1">
    <tr>
      <td>IP Address</td>
      <td>Click</td>
      <td>Ping</td>
    </tr>
    <tr>
      <td>192.168.1.0</td>
      <td><input name="ip" type="checkbox" onClick="checkbox_checked(0,'134.253.187.9')"></td>
      <td><input name="pingableText" type="text" disabled></td>
    </tr>
    <tr>
      <td>192.168.1.1</td>
      <td><input name="ip" type="checkbox" onClick="checkbox_checked(1,'134.253.187.251')"></td>
      <td><input name="pingableText" type="text" disabled></td>
    </tr>
  </table>
</form>
</body>
</html>

page returning ping results
Code:
<html> 
<cfoutput>
  <script language="javascript" type="text/javascript">
    function callback()
    { 
      var pingResults = document.#FormName#.hidden_ping_results.value;
      
      if (pingResults.search("alive") != -1)
        pingResults = "Response";
      
      else
        pingResults = "No Response";
      
      self.opener.set_pingable(#checkbox_key#,pingResults);
      window.close();
    }
  </script>
</cfoutput>
  <cfexecute name="ping" arguments="#ipaddress# 1" variable="pingResults" timeout="5"></cfexecute>
<cfoutput>
<body onLoad="callback();">
<form name="#FormName#">
  <input type="hidden" name="hidden_ping_results" value="#pingResults#">
</form>
</body>
</cfoutput>
</html>
 
You could create an empty div on the page, then use the ID of the div and document.getElementById(divname).innerHTML to fill in the data rather than a disabled textbox. Or you could set up a table with an IPs or app in one cell in a row, then use an ID in a second cell and write to that one using the above method.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top