Results 1 to 6 of 6

Thread: Javascript to replace all double quotes

  1. #1
    Join Date
    Mar 2010
    Posts
    162

    Javascript to replace all double quotes

    Hello,
    I am trying a java script function that can replace all the double quotes in my code. I have tried it but no success yet. so, if you have any solution for this then please let me know. Thank you for your help.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Javascript to replace all double quotes

    Hello,
    You can try using the escape character in your code, some thing like this
    Code:
    // Split a classnote into array by space
    var wds=classnote.split(" ")
    
    // Replace double quote(") to single quote (') through LOOP
    for(i=0;i<wds.length;i++)
    {
    clntsnotes = clntsnotes + wds[i].replace('"', '\'') + ' ';
    }

  3. #3
    Join Date
    Nov 2009
    Posts
    446

    Re: Javascript to replace all double quotes

    Hello,
    You can try the following
    Code:
    <?php
    	$query = 'insert into comment 
    		(comment_body) 
    		values ('There wasn't any way to accomplish it.');
    	myquery_query($query);
    ?>
    Hope this will work, if you have any more queries then you can post back with the error you are getting.

  4. #4
    Join Date
    Nov 2009
    Posts
    347

    Re: Javascript to replace all double quotes

    Hello,
    I think this is the code that you are looking for.
    HTML Code:
    <script type="text/javascript">
    function fix() {
      var numelem = document.theForm.elements.length;
      for (x=0; x<numelem; x++)  {
      // replace all the single, double quotes:
        var curElement = window.document.theForm.elements[x];
        curElement.value = curElement.value.replace(/\'/g, "&#56;");
        curElement.value = curElement.value.replace(/\"/g, "&#38;");
      }
      return true;
    }
    </script>

  5. #5
    Join Date
    Nov 2009
    Posts
    330

    Re: Javascript to replace all double quotes

    Hello,
    Have a look at the following code
    Code:
    <Script type="text/javascript">
    function func(stirng){return (stirng=stirng.replace(/["']{1}/gi,""));}
    
    //test for the function
    test="'''welcome to '''my site js.gainover.cn"\"\"\"'''";
    alert(func(test));
    </script>

  6. #6
    Join Date
    Nov 2009
    Posts
    356

    Re: Javascript to replace all double quotes

    Hello,
    Alternatively you can use the following code
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var striexam='Hi "how are" you';
    striexam=striexam.replace(/\"/g,'\'');
    alert(striexam);
    //-->
    </SCRIPT>
    
    Reply 6:
    Please check this modified code, may help you 
    <script type="text/javascript">
     <!--//
      function cntquts(string){
      return string.replace(/"/g,"'");
      }
    
    // EXAMPLE USAGE:
      document.write(cntquts('It"s is a test. It"s is a test.'));
     //-->
    </script>

Similar Threads

  1. Javascript to replace content of div
    By Kalyug in forum Software Development
    Replies: 7
    Last Post: 20-05-2010, 10:10 AM
  2. JavaScript - location.replace
    By Cordaro in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:55 PM
  3. Find and Replace in JavaScript String
    By Wilbur in forum Software Development
    Replies: 5
    Last Post: 15-12-2009, 02:23 PM
  4. How to Replace blank fields with Javascript
    By Aldous in forum Software Development
    Replies: 3
    Last Post: 18-08-2009, 03:43 PM
  5. Javascript to replace plus sign
    By Jagriti in forum Software Development
    Replies: 3
    Last Post: 22-06-2009, 08:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,981,010.93309 seconds with 16 queries