• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

function inside SERVER-SIDE

I have a function INSIDE SERVER SIDE. this function is used to substitute the single quote to double quote then insert the string to the Oracle database. THis script works fine if I put in the JS script. But when I put inside the SEVER-side, it does NOT RECONGISE THE S.LENGTH

please help this is very ugrent as our client need to do demo Tomorrow. many tahnks


The debug message shows below:

function replaceSingleQuote.s sfs | s.length:undefined  

Input value is : sfs
s.lenght        : undefined.


See my code below

<%

function replaceSingleQuote(s) {

  Response.write("<P>function       replaceSingleQuote.s " + s + " | s.length:" + s.length)  <===
  var returnString = "";
  for (i = 0; i < s.length; i++){  
    var c = s.charAt(i);
      Response.write("<P>function       replaceSingleQuote.c " + c)
      if (c=="'") {
         returnString = returnString + c + "'";
      }
      else {
            returnString = returnString + c;
      }
  }
  Response.write("<P>function       replaceSingleQuote.s " + s + " | after REPLACE.returnstring :" + returnString)
  return returnString;
}

while (!AppraisalFormDtl.EOF) {
  counter++
  var FreviewAnswer          = Request(FquestionCode)
  var TrimedReviewAnswer     = replaceSingleQuote(FreviewAnswer)
  Response.write("In while loop.TrimedReviewAnswer:" + TrimedReviewAnswer)
  if ((AppraisalFormDtl("rating_code"))=="NULL") {
      var SQLstatm = "UPDATE em_web_appraisal_form_dtl   " +
                     "  SET review_answer     =" + "DECODE('" + TrimedReviewAnswer     + "','undefined',''," + "'" + TrimedReviewAnswer + "')" +
                     " WHERE appraisal_form_id  = "  +  FappraisalFormId  +
                               " AND   question_code      = "  +  "'"  + FquestionCode      + "'"
  }
.
..
.
%>
0
LeanMoreTryMore
Asked:
LeanMoreTryMore
  • 8
  • 7
1 Solution
 
sajuksCommented:
cany u just use the replace function ?
  var TrimedReviewAnswer     = replace(FreviewAnswer, "'", "''")
0
 
LeanMoreTryMoreAuthor Commented:
Does it work in JScript?
0
 
sajuksCommented:
its a server side function  basically VBScript ...
jscript too has it
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsmthreplace.asp
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sajuksCommented:
heres an jscript example accomplishing what you are trying to do
http://www.4guysfromrolla.com/webtech/061800-1.shtml

code snippet
 var objRegExp = new RegExp("'", "gi");
  var strReplaceText = "''";        
  var strCommandText;
  strCommandText = "INSERT INTO tblTickets (userName, description, ";
  strCommandText += "severity)\nVALUES ('";
  strCommandText += strUser.replace(objRegExp, strReplaceText) + "', '";
  strCommandText += strDescription.replace(objRegExp, strReplaceText);
  strCommandText += "', " + intSeverity + ")\n";
   
  strCommandText += "SELECT @@IDENTITY AS tkt_id"

  //  here we escape any single quotes or SQL server will complain:
  strCommandText = strCommandText;
0
 
LeanMoreTryMoreAuthor Commented:
I tried the following but got error
The link you mentioned the above is for JScript .NET
I'm using ASP.jscript


function replaceSingleQuote(s) {
   Response.write("s:" + s);
   re = /"'"/g;          
   r = s.replace(re, "''");      <===== does not support this method
   return(r);                  
}


Error Type:
Microsoft JScript runtime (0x800A01B6)
Object doesn't support this property or method
/em/ReviewForm_action.asp, line 61


Please shed the light on this matter asap
0
 
sajuksCommented:
oops sorry,did u check the http://www.4guysfromrolla.com/webtech/061800-1.shtml link thats a classic asp function.

is there any reason why you cant just use the replace function...
  var TrimedReviewAnswer     = replace(FreviewAnswer, "'", "''")
0
 
LeanMoreTryMoreAuthor Commented:
I did try to use

var TrimedReviewAnswer     = replace(FreviewAnswer, "'", "''")   <=== line 69

but i got the following error

Error Type:
Microsoft JScript runtime (0x800A138F)
Object expected
/em/ReviewForm_action.asp, line 69

Do i need to specify the Jscript verion at the top of the ASP page

<%@LANGUAGE="JSCRIPT" %>
0
 
sajuksCommented:
nope see if this works
<%

sMyString = "Who's work is this?"
Response.Write "Actual > " &sMyString &"<BR>"
sMyString = Replace(sMyString, "'", "''")

Response.Write "Converted > " &sMyString

%>
0
 
LeanMoreTryMoreAuthor Commented:
<SCRIPT LANGUAGE="JavaScript" RUNAT=Server>
function replaceSingleQuote(s) {
   var objRegExp = new RegExp("'", "gi");
   var strReplaceText = "''";
   var strText = s.replace(objRegExp, strReplaceText);
   Response.write("<P>JavaScript.replaceSingleQuote.s:" + s + " | strText" + strText);
   return(r);                  
}
</SCRIPT>


Got the same error
Error Type:
Microsoft JScript runtime (0x800A01B6)
Object doesn't support this property or method
/em/Form_action.asp, line 61


Please advise if my setting is wrong or what...it keeps complaining not valid replace function
0
 
sajuksCommented:
thats odd,
<%

sMyString = "Who's work is this?"
Response.Write "createTicket > " &createTicket(sMyString)

%>


<script language='JavaScript' runat='server'>
function createTicket(strUser )
{
  var objRegExp = new RegExp("'", "gi");
  var strReplaceText = "''";                        
      strUser =strUser.replace(objRegExp, strReplaceText)
  return(strUser );
}
</script>

works fine for me...
0
 
LeanMoreTryMoreAuthor Commented:
Do I need to specify the IIS about JScript version? Please check your
0
 
sajuksCommented:
Whats ur setup that should've worked...can u just run the example above and see if thats working
0
 
LeanMoreTryMoreAuthor Commented:
no. it does NOT WORK.
see my whole page

Error Type:
Microsoft JScript compilation (0x800A03EC)
Expected ';'
/em/myTest.asp, line 6, column 15
Response.Write "createTicket > " &createTicket(sMyString);
--------------^


<%@LANGUAGE="JSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%

var sMyString = "Who's work is this?"
Response.Write "createTicket > " &createTicket(sMyString);

%>


<script language='JavaScript' runat='server'>
function createTicket(strUser )
{
  var objRegExp = new RegExp("'", "gi");
  var strReplaceText = "''";                    
     strUser =strUser.replace(objRegExp, strReplaceText);
       Response.Write("strUser:" + strUser);
  return(strUser );
}
</script>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

</body>
</html>


=========
Look like the problem associated with the configuration. BUT no idea.
I'm using IIS 5.1
0
 
sajuksCommented:
//check this, sorry my jscript level is almost nill
<%@LANGUAGE="JSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%

var sMyString = "Who's work is this?"
Response.Write ( "<BR>new val is "+createTicket(sMyString))

%>


<script language='JavaScript' runat='server'>
function createTicket(strUser )
{
  var objRegExp = new RegExp("'", "gi");
  var strReplaceText = "''";                    
     strUser =strUser.replace(objRegExp, strReplaceText);
      Response.Write("strUser:" + strUser);
  return(strUser );
}
</script>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

</body>
</html>
0
 
LeanMoreTryMoreAuthor Commented:
Very thanks sajuks

It works for the string which is a static variable like your example.

BUT NOT WORK for my case.

See below codes
==========

<%

var sMyString = "Who's work is this? - have single quote"
Response.Write("sMyString:" + sMyString)
Response.Write("<P>createTicket > " + replaceSingleQuote(sMyString))   <===== it works for this


var AppraisalFormDtl = Server.CreateObject("ADODB.Recordset")
var SQLAppraisalFormDtl = "SELECT rating_code, question_code " +
                          " FROM em_web_appraisal_form_dtl WHERE appraisal_form_id = " + FappraisalFormId +
                  " ORDER BY heading_no, DECODE(rating_code,'NULL',1,2), DECODE(form_section,'H',1,2) "
AppraisalFormDtl  = Cnxn.Execute(SQLAppraisalFormDtl)      
var FquestionCode = (AppraisalFormDtl("question_code"))

while (!AppraisalFormDtl.EOF) {
  counter++
  var FreviewAnswer          = replaceSingleQuote(Request(FquestionCode))
<**** error the above :  NOT WORK HERE IF FquestionCode is extracted from table  ==========>

  if ((AppraisalFormDtl("rating_code"))=="NULL") {
      var SQLstatm = "UPDATE em_web_appraisal_form_dtl   " +
                              "  SET review_answer     =" + "DECODE('" + FreviewAnswer     + "','undefined',''," + "'" +
                               FreviewAnswer + "')" +   " WHERE appraisal_form_id  = "  +  FappraisalFormId  +
                        " AND   question_code      = "  +  "'"  + FquestionCode      + "'"
  }
  Response.write("<P><P><P>" + SQLstatm)  
  Cnxn.Execute(SQLstatm)                 <==== error here
  AppraisalFormDtl.movenext
}


==================================================
I know its getting close.. please advise
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now