www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: Adding quote to server side variable

  1. #1
    Join Date
    Jun 2012
    Posts
    58

    Adding quote to server side variable

    How can I get this code to work?

    Code:
    <%@Language="JSCRIPT"%>
    <%
    
    function fixQuotes(aString)
    {
      sText = new String(aString);
      re = new RegExp("'",["g"]) ;
      sText = sText.replace(re,"''");
      return sText;
    }
    
    
    
    <head>
    <title>Floorplan Manager</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    
     function onCloneFloorObjects()
    {
     
      formFloorPlan.cloneof.value='<%=dspLayoutName%>';
      window.open("Clone.asp",'EditHTML','width=430,height=200,scrollbars=no');
    }
    The variable dspLayoutName contains the following text: "Mona's Test". How can I call the function fixquotes in the above line?

    Thanks.

  2. #2
    Join Date
    Nov 2010
    Posts
    1,049
    dunno much about ASP (that is ASP, right?), but wouldn't it be something like this:

    Code:
    formFloorPlan.cloneof.value=fixQuotes(<%=dspLayoutName%>);

  3. #3
    Join Date
    Jun 2012
    Posts
    58
    Quote Originally Posted by xelawho View Post
    dunno much about ASP (that is ASP, right?), but wouldn't it be something like this:

    Code:
    formFloorPlan.cloneof.value=fixQuotes(<%=dspLayoutName%>);
    Thanks for your suggestion but it didn't work. The function fixQuotes gets the following:

    Code:
    formFloorPlan.cloneof.value=fixQuotes(Mona's Test Layout);
    The apostrophe is causing an error. What I am expecting to happen is to have any apostrophes in the string replaced with double apostrophe, i.e. Mona''s Test Layout.

    How can I get this to work?

    Thanks.

  4. #4
    Join Date
    Nov 2010
    Posts
    1,049
    how about sending it as a string, something like...

    Code:
    formFloorPlan.cloneof.value=fixQuotes('"'+<%=dspLayoutName%>+'"');

  5. #5
    Join Date
    Jun 2012
    Posts
    58
    Thanks for the suggestion, however, it does not work. When the page first comes up the variable is empty and this is what I get:

    Code:
    formFloorPlan.cloneof.value=fixQuotes('"'++'"');
    This throws an error which will not allow me to run the process that populates the variable.

  6. #6
    Join Date
    Nov 2010
    Posts
    1,049
    umm.. check for the existence of the variable?

    Code:
    if(<%=dspLayoutName%>){
    formFloorPlan.cloneof.value=fixQuotes('"'+<%=dspLayoutName%>+'"');
    }
    ?

  7. #7
    Join Date
    Jun 2012
    Posts
    58
    I need to check for postback because this is what comes on the first pass.

    Code:
    if(){
      formFloorPlan.cloneof.value=fixQuotes('"'++'"');
      }
    The variable has not been populated yet.

    I wish I knew JS better.

  8. #8
    Join Date
    Nov 2010
    Posts
    1,049
    ah, I see - you might have to get a little bit roundabout then, but the advantage will be that you will have a string ready to work with. How about...
    Code:
    <script type="text/javascript"> 
    var myvar=<%=dspLayoutName%>;
    if(myvar){ //or if(myvar!="")
    formFloorPlan.cloneof.value=fixQuotes(myvar);
    }
    </script>

  9. #9
    Join Date
    Jun 2012
    Posts
    58
    Neither one worked. Thanks though.

    Here is what is rendered.
    Code:
    var myvar=;
    //if(myvar){ //or 
    if(myvar!=""){
    formFloorPlan.cloneof.value=fixQuotes(myvar);
    }

  10. #10
    Join Date
    Nov 2010
    Posts
    1,049
    I don't really understand the order that things happen in your code. Is it that the page loads, you then request a variable from the server and that populates the field? Because if that's the case you would want to incorporate a callback function to make sure the data is available before trying to use it.

  11. #11
    Join Date
    Jun 2012
    Posts
    58
    I'm sorry but I should have told you this from the beginning.

    The page displays a floor plan of the offices that we occupy. This is just an image. The user can then click on a button that opens a popup window which allows the user to select a layout (or seating chart). When the layout has been selected the page is refreshed from the popup before the popup is closed. This is when the variable, dspLayoutName, is populated.

    So the first time the page is loaded the variable is not populated and is causing the problem. I hope that this makes some sense and helps.

    Thanks.

  12. #12
    Join Date
    Nov 2010
    Posts
    1,049
    It seems to make sense. But why does the function need to run on page load if there is no data for it to work with? Is it not possible for it only to run once the user has closed the popup?

  13. #13
    Join Date
    Jun 2012
    Posts
    58
    Yes, if I only knew how to do that. This is not my code but I have been asked to make it work. It was written over 10 years ago and my boss wants it revived. I haven't done any coding in years. I am a project manager but we are short handed.

  14. #14
    Join Date
    Nov 2010
    Posts
    1,049
    I'm curious as to why this doesn't work:
    Code:
    <script type="text/javascript"> 
    var myvar=<%=dspLayoutName%>;
    if(myvar){ //or if(myvar!="")
    formFloorPlan.cloneof.value=fixQuotes(myvar);
    }
    </script>
    does it still fire the function, but with an empty value? You can test like this:

    Code:
    <script type="text/javascript"> 
    var myvar=<%=dspLayoutName%>;
    if(myvar){ //or if(myvar!="")
    alert(myvar)
    formFloorPlan.cloneof.value=fixQuotes(myvar);
    }
    </script>
    my understanding is that on initial page load you won't get the alert. If you do get an alert, what does it say?

  15. #15
    Join Date
    Jun 2012
    Posts
    58
    This is the code:
    Code:
    <script type="text/javascript">
    function onCloneFloorObjects()
    {
      if(!assertLayoutLoaded()) return false;
      
      var myvar=<%=dspLayoutName%>;
    //if(myvar){ //or 
    if(myvar!=""){
    formFloorPlan.cloneof.value=fixQuotes(myvar);
    }
    Here is the error:

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
    Timestamp: Fri, 5 Oct 2012 14:12:58 UTC


    Message: Syntax error
    Line: 519
    Char: 13
    Code: 0
    URI: http://houapptst07/floorplan/FloorMgr_Cleaned.asp

    Here is line 519:
    Code:
    function onCloneFloorObjects()
    {
      if(!assertLayoutLoaded()) return false;
      
      var myvar=;  <=== LINE 519
    //if(myvar){ //or 
    if(myvar!=""){
    formFloorPlan.cloneof.value=fixQuotes(myvar);
    }
    I hope this helps.
    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles