Solved

checkbox onclick

Posted on 2000-03-09
8
2,720 Views
Last Modified: 2008-05-09
Can You do This??

I have a checkbox but when clicked I want it to call an vb server side function only when its clicked.  It seems to be calling the function(funtix) every time I write the checkbox not when the user clicks it?  here is my code:



<tr bgcolor="#EFEFEF">
                  <td align=left width=5%><input type=checkbox onclick"<%Call funtix(strTickets2) %>" name=<%Response.Write strTickets2%> value = 2   id=checkbox1 CHECKED></td>
                  <td width = 20%><font face="Arial, Helvetica, sans-serif" size=-1><%Response.Write rsTemp2.Fields("ticket") %></td>
                  </tr>
                  

Any suggestions or ideas??
Thank You!
0
Comment
Question by:Aimyee
8 Comments
 

Author Comment

by:Aimyee
Comment Utility
To clarify:  What I need to do is keep the name of the checkbox in a Session variable.  Becuase on this page I have a link for users to add a name but when they come back to the asp if they have checked any of the checkboxes they are unchecked.  Any ideas on how to keep what the user has checked without using a submit button?

Thanks again..
0
 
LVL 4

Expert Comment

by:FRehman
Comment Utility
<%
if request.form("chk1") then
str="Sdfd"
end if
%>
<html>
<script language="Javascript">
       function test()
{
document.form1.action="thispage.asp"
document.form1.submit()
}
</script>
<body>
<form name=form1 action="" method=post>
<table>
<tr bgcolor="#EFEFEF">
<td align=left width=5%>
<input type=checkbox name=chk1 value = 2 CHECKED onclick="test()"></td>
<td width = 20%><font face="Arial, Helvetica, sans-serif" size=-1><%Response.Write str %></td>
</tr>
</table>
</body>
</form>
this is better way to send request to server and get the value from there
0
 
LVL 1

Expert Comment

by:jbathija
Comment Utility
You cannot merge client side script and server side script together. For that you need to be able to know to use remote scripting where you click i.e client side script calls a server side script without the user actually knowing that it was a server sie script.

It makes use of the rsproxy.java class provided by Microsoft to implement Remote Scripting.
0
 
LVL 15

Accepted Solution

by:
robbert earned 100 total points
Comment Utility
Aimyee,

jbathija is right, you can do the job by Remote Scripting. I have customized a script for you - it should be failsafe to use.

The script will do the following:
If the user clicks the checkbox, strTickets2 will be written to a server-side session variable. If the checkbox is checked, a session variable, called like the value of strTickets2, will be set to True, otherwise set to False.
Just in order to demonstrate that the client is able to receive a return value from the server, there is a JavaScript AlertBox that informs the user of the ordering status.

There are three files.
order.asp is your original order page.
rs.htm, and rs.asp, are Microsoft files to enable Remote Scripting. Put them into the same directory as order.asp.
You can download them at www.microsoft.com/scripting, too, but I wanted to provide a failsafe solution, being ready to use. (Sorry for the long code, then.)

BTW, this is not easy, but newest high-tech and, highly customized for you. I would be happy if you'ld increase the points. - If you can't, never mind, it was a fun for me.


Here we go:

########################################

order.asp;

<% @Language = VBScript %>
<%
RSDispatch 'initialize Remote Scripting

strTickets2 = "TestTicket" 'you will generate this string somehow

Function funtix(strWhat, blnChecked)
    Session("Ticket") = strWhat
    Session(strWhat) = blnChecked
    If blnChecked Then
        funtix = "You have ordered a ticket: " & strWhat
    Else: funtix = "You did not order the ticket: " & strWhat
    End If
End Function
%>

<!--#INCLUDE FILE="rs.asp"-->

<script language=javascript runat=server>
function Description() {
    this.funtix2 = funtix2
}
function funtix2(strWhat, blnChecked) {
    return funtix(strWhat, blnChecked)
}
public_description = new Description()
</script>

<HTML>
<HEAD>
<script language="JavaScript" src="rs.htm"></script>
<script language="JavaScript">
    RSEnableRemoteScripting("") // path to rs.htm
   
    var urlServer = "order.asp" // this page's name
   
    function funtix(strWhat, strObjName) {
        var blnChecked = eval("document.forms[0]." + strObjName + ".checked")
        var co = RSExecute(urlServer,"funtix2", strWhat, blnChecked)
            alert(co.return_value)
    }
</script>
</HEAD>
<BODY>

<form id=form1 name=form1>
<input type=checkbox onclick="funtix('<%=strTickets2%>', this.name)"
name="<%Response.Write strTickets2%>">Order ticket
</form>

</BODY>
</HTML>


########################################

rs.htm;

      //*****************************************************************
      // Microsoft Scripting Libary 1.0a
      // Remote Scripting utilities for client.
      //
      //      The Remote Scripting utilities for the client consist of
      //      three public methods and the RSCallObject definition.
      //      The public methods are RSEnableRemoteScripting, RSExecute
      //      and RSGetASPObject. The RSCallObject is returned from any
      //      remote scripting call and provides status and return value.
      //
      // Copyright 1999 Microsoft Corporation. All Rights Reserved.
      //*****************************************************************
      
      //*****************************************************************
      // function RSEnableRemoteScripting()
      //      This function enables the remote scripting proxy.
      //*****************************************************************
      function RSEnableRemoteScripting(codebase)
      {
            MSRS = new _MSRS_Object();
            if (typeof(codebase) == 'undefined')
            {      // assume applet is in _ScriptLibrary directory off the webroot
                  var secondSlash, path;
                  codebase = '';
                  if ((secondSlash = (path = window.location.pathname).indexOf('/',1)) != -1)
                        codebase = path.substring(0,secondSlash);
                  codebase += '/_ScriptLibrary';
            }
            document.write('<' + 'APPLET name=RSAspProxyApplet codebase=' + codebase + ' code=RSProxy.class height=0 width=0></APPLET>');      
      }

      //*****************************************************************
      // function RSExecute(url,method,p1 ... pn,cb,ecb,context)
      //      This is the function by which remote scripting calls are made.
      //      The caller provides the following :
      //            url            : url to the asp file containing remote script
      //            method      : name of the method to be invoked
      //            p1...pn      : any parameters required by the method
      //            cb            : an optional callback routine for async.
      //            ecb            : an optional error callback routine for async.
      //            context      : an optional user context
      //*****************************************************************
      function RSExecute(url,method)
      {
            var cb, ecb, context;
            var params = new Array;
            var pn = 0;
            var len = RSExecute.arguments.length;
            for (var i=2; i < len; i++)
                  params[pn++] = RSExecute.arguments[i];
            
            return MSRS.invokeMethod(url,method,params);
      }

      //*****************************************************************
      // function RSGetASPObject(url)
      //      This function returns a server object for an ASP file
      //      described by its public_description.
      //*****************************************************************
      function RSGetASPObject(url)
      {
            var cb, ecb, context;
            var params = new Array;
            var request = MSRS.startRequest(url,'GetServerProxy',params,cb,ecb,context);
            //alert(request.data);      // USED FOR DEBUG
            if (request.status == MSRS_COMPLETED)
            {
                  var server = request.return_value;
                  if (typeof(Function) == 'function')
                  {
                        for (var name in server)
                              server[name] = Function('return MSRS.invokeMethod(this.location,"' +  name + '",this.' + name + '.arguments);');
                  }
                  else
                  {      // JavaScript 1.0 does not support Function  ( IE3.0 )
                        for (var name in server)
                              server[name] = eval('function t(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,pA,pB,pC,pD,pE,pF) { return MSRS.invokeMethod(this.location,"' + name + '",this.' + name + '.arguments);} t');
                  }
                  server.location = url;
                  return server;
            }
            alert('Failed to create ASP object for : ' + url);
            return null;
      }

      //*****************************************************************
      // function RSCallObject(cb,ecb,context)
      //
      //      The RSCallObject is returned for every remote scripting
      //      invocation. It contains the return value and status.
      //
      //            id                        :      unique id of request
      //            status                  :      status of request, one of
      //                                                MSRS_COMPLETED
      //                                                MSRS_FAIL
      //                                                MSRS_PENDING
      //                                                MSRS_PARTIAL
      //            message                  :      message associated with status
      //            data                  :      raw data returned from server
      //            return_value      :      evaluated value returned from server
      //            callback            :      user provided callback ( optional )
      //            error_callback      :      user provided callback ( optional )
      //            context                  :      user provided context ( optional )
      //
      //*****************************************************************
      function RSCallObject(cb,ecb,context)
      {
            this.id = MSRS.nextRequestID++;
            this.status = MSRS_PENDING;
            this.message = '';
            this.data = '';
            this.return_value = '';
            
            this.callback = cb;
            this.error_callback = ecb;
            this.context = context;

            this.wait = RSCallObject_wait;
            this.cancel = RSCallObject_cancel;

            MSRS.requestList[this.id] = this;
      }

      //*****************************************************************
      // function RSCallObject_wait()
      //
      //      The RSCallObject_wait method can be called from an asynchronous
      //  request to wait for it to complete.  If the request has finished
      //  this call returns immediately.
      //
      //            this = RSCallObject instance to wait for
      //*****************************************************************
    function RSCallObject_wait()
      {
            if (this.status != MSRS_PENDING)
                  return;
            while (true)
            {      // wait synchronously for response
                  if (MSRS.rsapplet.waitForResponse())
                  {
                        if (MSRS.rsapplet.hasResponse())
                        {
                              var rid = MSRS.rsapplet.getRequestID();
                              MSRS.handleResponse(rid);
                              // DO NOT CHANGE THIS CODE
                              // Solves Java to Script discrepancies between IE3 and Navigator
                              var strrid = String(rid);
                              if (strrid == null)
                                    strrid = rid;
                              if (strrid == this.id)      
                                    break;                        // this response completed                  
                        }
                  }
                  else
                  {
                        this.status = MSRS_FAIL;
                        this.message = 'Request not handled.'
                        break;
                  }
            }
      }

      //*****************************************************************
      // function RSCallObject_cancel()
      //
      //      The RSCallObject_cancel method can be called from an
      //      asynchronous request to cancel it.  If the request has
      //      finished this call returns immediately.
      //
      //            this = RSCallObject instance to cancel
      //*****************************************************************
    function RSCallObject_cancel()
      {
            if (this.status == MSRS_PENDING)
            {
                  MSRS.rsapplet.cancelRequest(this.id);
                  this.status = MSRS_FAIL;
                  this.message = 'Request cancelled.'
            }
      }

      //*** PRIVATE IMPLEMENTATION BELOW ********************************
      //*** PRIVATE IMPLEMENTATION BELOW ********************************
      //*** PRIVATE IMPLEMENTATION BELOW ********************************
      //*****************************************************************
      //
      // Remote Scripting Object --  private implementation
      //
      //      The following code is private glue code that contains the
      //      implementation of a JSObject to enable remote scripting
      //      functionality on the client. This private object is utilized
      //      by the public Remote Scripting methods defined above.
      //
      //*****************************************************************
      //*****************************************************************

      //*****************************************************************
      // function _MSRS_Object
      //
      //      This is the JSObject that interacts with the RSAspProxy
      //      applet to synchronously/asynchronously retrieve data via
      //      an ASP file.
      //*****************************************************************
      //var MSRS = new _MSRS_Object();
      function _MSRS_Object()
      {
            MSRS_FAIL = -1;
            MSRS_COMPLETED = 0;
            MSRS_PENDING = 1;
            MSRS_PARTIAL = 2;

            this.REQUEST_MODE_COMPLETE = 0;
            this.POLLING_PERIOD = 100;

            this.pollID = 0;
            this.pollCount = 0;
            this.nextRequestID = 1;
            this.requestList = new Array;
            this.rsapplet = null;

            this.startRequest = _MSRS_startRequest;
            this.invokeMethod = _MSRS_invokeMethod;
            this.handleResponse = _MSRS_handleResponse;
            this.evaluateRequest = _MSRS_evaluateRequest;
            this.setRequestPoll = _MSRS_setRequestPoll;
            this.requestPollHandler = _MSRS_requestPollHandler;
            this.buildURL = _MSRS_buildURL;
      }

      //*****************************************************************
      // function _MSRS_startRequest(url,method,args,cb,ecb,context)
      //
      //      This is key function for initiating a request for data.
      //      The url to the ASP file is required. The callback,
      //      error_callback, and user context parameters are optional.
      //*****************************************************************
      function _MSRS_startRequest(url,method,args,cb,ecb,context)
      {
            var request = new RSCallObject(cb,ecb,context);
            if (this.rsapplet == null)
            {
                  if (typeof(document.RSAspProxyApplet) == 'object')
                        this.rsapplet = document.RSAspProxyApplet;
                  else if (typeof(document.thisForm) == 'object' && typeof(document.thisForm.RSAspProxyApplet) == 'object')
                        this.rsapplet = document.thisForm.RSAspProxyApplet;
                  else
                  {
                        errmsg = 'ERROR:\nCannot locate proxy which supports Remote Scripting.\nWas RSEnableRemoteScripting method invoked?';
                        request.status = MSRS_FAIL;
                        request.message = errmsg;
                        alert(errmsg);
                  }
            }

            if (request.status != MSRS_FAIL)
            {
                  url = this.buildURL(url,method,args);
                  url_context = window.location.href; // May not be 'window.location.pathname'
                  this.rsapplet.startRequest(request.id,url_context,url,this.REQUEST_MODE_COMPLETE);
                  if (typeof(cb) == 'function')
                  {
                        if (this.pollCount++ == 0)
                              this.setRequestPoll();
                  }
                  else
                  {      // wait synchronously for response
                        request.wait();
                  }
            }
            return request;
      }

      //*****************************************************************
      // function _MSRS_invokeMethod(url,method,args)
      //      This is the function by which remote scripting calls are
      //      via a server object retrieved with the GetASPObject call.
      //      The caller provides the following :
      //            url            : url to the asp
      //            method      : name of the method to be invoked
      //            args      : an array containing method parameters
      //                          and the optional cb, ecb, context parameters
      //*****************************************************************
      function _MSRS_invokeMethod(url,method,args)
      {
            var cb, ecb, context;
            var params = new Array;
            var pn = 0;
            var i = 0;
            for (var i=0; i < args.length; i++)
            {
                  if (typeof(args[i]) == 'function')
                  {
                        pn = -1;      // no more params
                        if (typeof(cb) == 'undefined')
                              cb = args[i];
                        else
                              ecb = args[i];
                  }
                  else if (pn != -1)
                  {
                        params[pn++] = args[i];
                  }
                  else
                        context = args[i];
            }

            return MSRS.startRequest(url,method,params,cb,ecb,context);
      }

      //*****************************************************************
      // function _MSRS_handleResponse(requestid)
      //
      //      This function will handle the response for a given request.
      //      If the response is complete or failed, then the associated
      //      request object will be updated and the appropriate callback
      //      invoked, if provided.
      //      NOTE: incremental data retrieval is not yet supported
      //*****************************************************************
      function _MSRS_handleResponse(requestid)
      {
            var request = this.requestList[requestid];
        if (typeof(request) == 'undefined')
            {
            alert('Unknown request id.');
                  return;
            }

        request.status = this.rsapplet.getStatus();
        if (request.status == MSRS_COMPLETED)
            {
                  request.data = this.rsapplet.getData();
                  request.message = this.rsapplet.getMessage();
                  this.evaluateRequest(request);
                  if (request.status == MSRS_FAIL)
                  {      
                        if (typeof(request.error_callback) == 'function')
                        {
                              this.pollCount--;
                              request.error_callback(request);
                        }
                        else
                              alert('Remote Scripting Error\n' + request.message);
                  }
                  else
                  {
                        if (typeof(request.callback) == 'function')
                        {
                              this.pollCount--;
                              request.callback(request);
                        }
                  }
                  this.rsapplet.endResponse();
                  this.requestList[request.id] = null;
            }
        else if (request.status == MSRS_FAIL)
            {
                  request.message = this.rsapplet.getMessage();
                  if (typeof(request.error_callback) == 'function')
                  {
                        this.pollCount--;
                        request.error_callback(request);
                  }
                  this.rsapplet.endResponse();
                  this.requestList[request.id] = null;
            }
        else if (request.status == MSRS_PARTIAL)
            {      // not handling partial data retrieval yet
            }
        else if (request.status == MSRS_PENDING)
            {      // do nothing
            }
      }

      //*****************************************************************
      // function _MSRS_evaluateRequest(request)
      //
      //      This function evaluates the data returned to the request.
      //      Marshalled jscript objects are re-evaluated on the client.
      //*****************************************************************
      function _MSRS_evaluateRequest(request)
      {
            var data = request.data;
            var start_index = 0;
            var end_index = 0;
            var start_key = '<' + 'RETURN_VALUE';
            var end_key = '<' + '/RETURN_VALUE>';

            if ((start_index = data.indexOf(start_key)) != -1)
            {
                  var data_start_index = data.indexOf('>',start_index) + 1;
                  end_index = data.indexOf(end_key,data_start_index);
                  if (end_index == -1)
                        end_index = data.length;
                  var metatag = data.substring(start_index,data_start_index);
                  if (metatag.indexOf('TYPE=SIMPLE') != -1)
                  {
                        request.return_value = unescape(data.substring(data_start_index,end_index));
                        //alert('TYPE=SIMPLE:\n' + data);      // USED FOR DEBUG
                  }
                  else if (metatag.indexOf('TYPE=EVAL_OBJECT') != -1)
                  {
                        request.return_value = data.substring(data_start_index,end_index);
                        //alert('TYPE=EVAL_OBJECT:\n' + data);      // USED FOR DEBUG
                        request.return_value = eval(unescape(request.return_value));
                  }
                  else if (metatag.indexOf('TYPE=ERROR') != -1)
                  {
                        request.status = MSRS_FAIL;
                        request.message = unescape(data.substring(data_start_index,end_index));            
                  }
            }
            else
            {
                  request.status = MSRS_FAIL;
                  request.message = 'REMOTE SCRIPTING ERROR: Page invoked does not support remote scripting.';                  
            }
      }

      //*****************************************************************
      // function _MSRS_setRequestPoll()
      //
      //      Due to limitations in calling back into JScript from a worker
      //      thread of an applet, a polling mechanism is used to determine
      //      when a request has been completed. This function sets up
      //      a timer to kick the requestPollHandler at a later time.
      //*****************************************************************
      function _MSRS_setRequestPoll()
      {
            this.pollID = window.setTimeout('MSRS.requestPollHandler()',this.POLLING_PERIOD,'javascript');
      }

      //*****************************************************************
      // function _MSRS_requestPollHandler()
      //
      //      Due to limitations in calling back into JScript from a worker
      //      thread of an applet, a polling mechanism is used to determine
      //      when a request has been completed. This function is the
      //      handler which is kicked by a timer. It polls the applet to
      //      see if a response to a prior request is available.
      //*****************************************************************
      function _MSRS_requestPollHandler()
      {
        while (this.rsapplet.hasResponse())
        {
                  this.handleResponse(this.rsapplet.getRequestID());
            }
        if (this.pollCount != 0)
            this.setRequestPoll();
      }

      //*****************************************************************
      // function _MSRS_buildURL(url,method,args)
      //
      //      This builds the proper url entry point into the ASP page
      //      such that the intended server method with parameters gets
      //      invoked.
      //*****************************************************************
      function _MSRS_buildURL(url,method,args)
      {
            if (url == '') url = window.location.pathname;
            if (typeof(method) == 'string')
            {
                  url += '?_method=' + method;
                  url += '&_mtype=execute';
                  var params = '&pcount=0';
                  if (typeof(args) != 'undefined' && args.length)
                  {      // add parameters
                        params = '&pcount=' + args.length
                        for (var i = 0; i < args.length; i++)
                        {
                              var arg = args[i];
                              params += '&p' + i + '=' + escape(arg);
                        }
                  }
                  url += params;
            }
            return url;
      }


########################################

rs.asp;

 <SCRIPT RUNAT=SERVER Language="JavaScript">
//*****************************************************************
// MSL : Microsoft Scripting Libary 1.0a
// Remote Scripting utilities for server.
//
//      The Remote Scripting utilities for the server primarily
//      consists of the RSDispatch routine.  This is the function
//      placed at the top of the ASP page which handles dispatching
//      to a valid public_description function and marshalls the
//      return value back to the client.
//
// Copyright 1999 Microsoft Corporation. All Rights Reserved.
//*****************************************************************

//*****************************************************************
// function RSDispatch()
//      This function is used to dispatch to the proper server
//      function in the public_description object based on the
//      Request.QueryString("_method") parameter passed in.
//
//*****************************************************************
function RSDispatch(vtable,methodname)
{
      if (typeof(methodname) != 'string')
      {
            var methodtype = Request.QueryString('_mtype') + '';
            if (methodtype != 'execute')
                  return false;
            methodname = Request.QueryString('_method') + '';
            if (methodname == '' || methodname == 'undefined')
                  return false;
      }

      var dispatchVTbl = null;
      if (typeof(vtable) == 'object')
            dispatchVTbl = vtable;
      else if (typeof(public_description) == 'object')
            dispatchVTbl = public_description;
      if (dispatchVTbl == null)
            return false;

      var strResponse = '<METHOD VERSION="1.0.8044">'
      if (methodname == 'GetServerProxy')
      {
            strResponse += Return(GetServerProxy(dispatchVTbl));
      }
      else
      {
            if (typeof(dispatchVTbl[methodname]) == 'function' || typeof(dispatchVTbl[methodname]) == 'unknown')
            {      // validate function is in dispatchVTbl
                  var params = '';
                  var pcount = Request.QueryString('pcount');
                  for (var i=0; i < pcount; i++)
                  {      // extract parameter values
                        var param = Request.QueryString('p'+i);
                        params += '"' + param + '"';
                        if (i < pcount-1)
                              params += ',';
                  }

                  var dispatch = 'dispatchVTbl.' + methodname + '(' + params + ')';
                  //Response.write(dispatch);      // USED FOR DEBUG
                  // validated against dispatchVTbl, safe to eval on the server
                  var r = eval(dispatch);
                  strResponse += Return(r);
            }
            else
            {
                  var strError = '<RETURN_VALUE TYPE=ERROR>';
                  strError += escape(methodname + ' : not a public function');
                  strError += '</RETURN_VALUE>';
                  strResponse += strError;
            }
      }
      strResponse += '</METHOD>';
      
      Response.Write(strResponse);
      return true;
}

//*****************************************************************
// function Return(x)
//      This function is used to translate the data in given variable x,
//      into a string for transport to the client.  If the variable
//      is an object, then the type is set to EVAL_OBJECT to indicate
//      to the client that this is an object being marshalled and it
//      should be "evaluated".  
//*****************************************************************
function Return(x)
{
      var returnType = typeof(x);
      if (returnType == 'object' || returnType == 'number' || returnType == 'boolean')
            return '<RETURN_VALUE TYPE=EVAL_OBJECT>' + escape(uneval(x)) + '</RETURN_VALUE>';
      else
            return '<RETURN_VALUE TYPE=SIMPLE>' + escape(x) + '</RETURN_VALUE>';
}

//*****************************************************************
// function GetServerProxy(pd)
//      This function returns a server proxy given a public_description.
//
//*****************************************************************
function GetServerProxy(pd)
{
      if (!unevalInitialized)
      {
            initUneval();
            unevalInitialized = true;
      }

      var o = new Object;
      for (var name in pd)
      {
            if (typeof(pd[name]) == 'function'  && pd.__isPublicMember(name))
            {
                  o[name] = Function('return 0;');
            }
            else
            //  Do we have a VBScript object?
            if (typeof(pd[name]) == 'unknown')
            {
                  o[name] = Function('return 0;');
            }      
      }
      return o;
}


//*****************************************************************
// function uneval(obj)
//      This function takes a given jscript object and creates a
//      string representing the object instance in its current state,
//      such that when the string is "evaluated" with the "eval"
//      function, the object will be recreated. This function is used
//      to to "marshall" jscript objects across the client/server
//      boundary.
//
//*****************************************************************
var unevalInitialized;
var unevalNextIdentifier;
function unevalGetNextID()
{
      return '_o' + unevalNextID++;
}

function uneval(obj)
{
      if (!unevalInitialized)
      {
            initUneval();
            unevalInitialized = true;
      }
      unevalNextID = 0;
      var s = 'var undefined;' + unevalDecl(obj) + unevalInst(obj);
      unevalClear(obj);
      return s;
}

function unevalDecl(obj)
{
      var s = '';
      switch (typeof(obj))
      {
            case 'undefined':
            case 'boolean':
            case 'number':
            case 'string':
                  break;

            default:
                  if (null != obj && !obj.__mark && 'string' != typeof(obj.__decl))
                        {
                        obj.__mark = true;
                        obj.__decl = unevalGetNextID();
                        s = obj.__unevalDecl();
                        delete obj.__mark;
                        }
                  break;
      }
      return s;
}

function unevalInst(obj)
{
      var s = '';
      switch (typeof(obj))
      {
            case 'undefined':
                  s = 'undefined';
                  break;
            case 'boolean':
            case 'number':
                  s = String(obj);
                  break;
            case 'string':
                  s = unevalString(obj);
                  break;

            default:
                  if (null == obj)
                        s = 'null';
                  else if (obj.__mark)
                        s = '"ERROR: Cycle in uneval graph."';
                  else
                        {
                        obj.__mark = true;
                        s = obj.__unevalInst();
                        delete obj.__mark;
                        }
                  break;
      }
      return s;
}

function unevalClear(obj)
{
      switch (typeof(obj))
      {
            case 'undefined':
            case 'boolean':
            case 'number':
            case 'string':
                  break;

            default:
                  if (null != obj && !obj.__mark && 'string' == typeof(obj.__decl))
                  {
                        obj.__mark = true;
                        obj.__unevalClear();
                        delete obj.__mark;
                  }
                  break;
      }
      return ;
}

function unevalDoNothing()
{      }

function unevalConvertToString(obj)
{      return String(obj);            }

function unevalString(str)
{      return '"' + str.replace(/([^\\])'/g,'$1\\"') + '"';       }


//*****************************************************************
// function initUneval()
//
//      This function sets up the prototype __uneval functions that
//  are used to support uneval function for all data types.
//
//*****************************************************************
function initUneval()
{
      // instrinsic objects
      Object.__unevalDecl = unevalDoNothing;
      Object.__unevalInst = function () { return 'Object'; }
      Object.__unevalClear = unevalDoNothing;

      Boolean.__unevalDecl = unevalDoNothing;
      Boolean.__unevalInst = function () { return 'Boolean'; }
      Boolean.__unevalClear = unevalDoNothing;

      Number.__unevalDecl = unevalDoNothing;
      Number.__unevalInst = function () { return 'Number'; }
      Number.__unevalClear = unevalDoNothing;

      String.__unevalDecl = unevalDoNothing;
      String.__unevalInst = function () { return 'String'; }
      String.__unevalClear = unevalDoNothing;

      Date.__unevalDecl = unevalDoNothing;
      Date.__unevalInst = function () { return 'Date'; }
      Date.__unevalClear = unevalDoNothing;

      Function.__unevalDecl = unevalDoNothing;
      Function.__unevalInst = function () { return 'Function'; }
      Function.__unevalClear = unevalDoNothing;

      Array.__unevalDecl = unevalDoNothing;
      Array.__unevalInst = function () { return 'Array'; }
      Array.__unevalClear = unevalDoNothing;

      // object members
      Object.prototype.__enumMembers = function(retval,func)
      {
            var isPublicMember = this.__isPublicMember;
            if ('object' == typeof(this.__unevalProperties))
            {
                  var unevalProperties = this.__unevalProperties;
                  var length = unevalProperties.length;
                  for (var i = 0; i < length; i++)
                  {
                        if (isPublicMember(unevalProperties[i]))
                              func(retval, this, unevalProperties[i]);
                  }
            }
            else
            {
                  for (var i in this)
                  {
                        if (isPublicMember(i))
                              func(retval, this, i);
                  }
            }
      }

      Object.prototype.__unevalDeclMember = function (retval, obj, member)
      {
            retval.otherDecl += unevalDecl(obj[member]);
            retval.myDecl += obj.__decl + '[' + unevalString(member) + ']=' + unevalInst(obj[member]) + ';';
      }

      Object.prototype.__unevalDecl = function()
      {
            var retval = { otherDecl:'', myDecl:'' };
            this.__enumMembers(retval, this.__unevalDeclMember);
            return retval.otherDecl + 'var ' + this.__decl + '=' + this.__unevalConstructor() + ';' + retval.myDecl;
      }

      Object.prototype.__unevalInst = function ()
      {      return this.__decl;            }

      Object.prototype.__unevalClearMember = function(retval, obj, member)
      {      unevalClear(obj[member]);      }

      Object.prototype.__unevalClear = function()
      {
            delete this.__decl;
            this.__enumMembers(null, this.__unevalClearMember);
      }

      Object.prototype.__isPublicMember = function(member)
      {      return '__' != member.substr(0,2);            }

      Object.prototype.__unevalConstructor = function ()
      {      return 'new Object';            }

      // overrides for simple types
      Boolean.prototype.__unevalConstructor = function()
      {      return 'new Boolean(' + String(this) + ')';      }
      Number.prototype.__unevalConstructor = function()
      {      return 'new Number(' + String(this) + ')';      }
      String.prototype.__unevalConstructor = function()
      {      return 'new String(' + unevalString(this) + ')';      }
      Date.prototype.__unevalConstructor = function()
      {      return 'new Date(Date.parse("' + String(this) + '"))';      }

      // overrides for function
      Function.prototype.__unevalDecl = function()
      {      return String(this).replace(/function ([^\(]*)/,'function ' + this.__decl);      }

      // overrides for array
      Array.prototype.__unevalDecl = function()
      {
            var decl = this.__decl;
            var r = '';    
            var s = 'var ' +  decl + '= new Array(' + this.length + ');';
            var length = this.length;
            for (var i = 0; i < length; i++)
            {
                  r += unevalDecl(this[i]);
                  s += decl + '[' + i + ']=' + unevalInst(this[i]) + ';';
            }
            return r + s;
      }

}      // end of initUneval

</SCRIPT>
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Expert Comment

by:robbert
Comment Utility
Sorry, you'll need a fourth file; Rsproxy.class. You'll get it at http://msdn.microsoft.com/scripting/remotescripting/rsdown.htm.
Have fun!
0
 

Author Comment

by:Aimyee
Comment Utility
Adjusted points from 50 to 100
0
 

Author Comment

by:Aimyee
Comment Utility
Thank You , sorry I don't have many points! But Thank You!
0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
That's great, isn't it? Also read the docs coming with the download.
I just built it in into a big, real world application and it does not stop when building more complex jobs.
Imagine the possibilities with a good knowledge of JavaScript.

BTW, thanks for the points. I didn't mean to get your last points.

Until you get it working, you can ask questions here.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now