Results 1 to 6 of 6

Thread: How to change a variable that is saved in an object structure in JavaScript?

  1. #1
    Join Date
    Jul 2006
    Posts
    273

    How to change a variable that is saved in an object structure in JavaScript?

    I am facing a problem in JavaScript. I tried to search a lot but didn't get the desired answer. Also I tried to do lot of coding, which also didn't worked. I want to select some text and click that button. JavaScript should read the text I selected, when I click the button. Also I want to change the value that he has read. Also I am having a doubt that how to change a variable that is saved in an object-structure.?? Please help me soon..!!
    (\__/)
    (='.'=) This is Bunny. Copy and paste bunny into your
    (")_(") signatureto help him gain world domination

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to change a variable that is saved in an object structure in JavaScript?

    Using the JavaScript that I have provided, your script will read the text that you are selecting, when you click the button. Here is the script for that :
    Code:
    <script type="text/javascript">
    <!--
    function getSelText()
    {
        var foundIn = '';
        var txt = '';
        if (window.getSelection)
        {
        
            txt = window.getSelection();
            
            
        }
        else if (document.getSelection)
        {
            txt = document.getSelection();
            
        }
        else if (document.selection)
        {
            txt = document.selection.createRange().text;
            
        }
        else return;
    
        s = document.aform.selectedtext.value;
        document.write(s);
        s = s.replace(/Chr(8)/g,"\r");
        document.aform.selectedtext.value = s;
    
        document.aform.selectedtext.value = replace(document.aform.selectedtext.value, /Chr(8)/, "\r")
    
        document.aform.selectedtext.value = document.aform.selectedtext.value + "\r" + txt;
    }
    // -->
    </script>

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: How to change a variable that is saved in an object structure in JavaScript?

    I think that the script mentioned by the 'void' should be changed a bit. The string "object" has a replace method built-in. The following is an example for that :
    Code:
    var str = 'this is a trial';
    document.write(str.replace("is","was"));
    Using this script, it would print "this was a trial". A regular expression as search pattern can also be used.

  4. #4
    Join Date
    Jul 2006
    Posts
    289

    Re: How to change a variable that is saved in an object structure in JavaScript?

    The method replace() searches for a match between a substring and a string. It also searches for a match between regular expression. And then after searching it replaces the matched substring with a new substring. Here is a Syntax for replace() :
    Code:
    string.replace(regexp/substr,newstring)
    Parameters of replace() are :
    • newstring - this is required for the string to replace the found value in parameter 1.
    • regexp/substr - this is required for a substring or a regular expression.
    Signatures reduce available bandwidth

  5. #5
    Join Date
    Aug 2006
    Posts
    227

    Re: How to change a variable that is saved in an object structure in JavaScript?

    You can also track an object structure change without any trigger. SQL Server 2005 provides you an excellent way to find when the table was last modified without adding any extra load on database. Following TSQL script gives you the last modified date of your table. Just replace the object name from testTable to your own object.
    Code:
    A select name,modify_date from sys.objects
    Where name =‘testTable’
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  6. #6
    Join Date
    Jul 2006
    Posts
    286

    Re: How to change a variable that is saved in an object structure in JavaScript?

    If you want to perform a case-sensitive search, then you can use the following script :
    Code:
    <script type="text/javascript">
    
    var str="Visit Google!";
    document.write(str.replace("Google", "TechArena"));
    
    </script>
    And if you want to perform a case-insensitive search, then following script would be useful :
    Code:
    <script type="text/javascript">
    
    var str="Visit Google!";
    document.write(str.replace(/google/i, "TechArena"));
    
    </script>
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

Similar Threads

  1. Replies: 3
    Last Post: 08-01-2011, 05:20 AM
  2. How to setup a JavaScript Object Notation variable?
    By hatred in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 01:25 AM
  3. Passing Javascript variable value into JSP scriptlet
    By ComPaCt in forum Software Development
    Replies: 3
    Last Post: 23-09-2009, 03:32 PM
  4. Replies: 2
    Last Post: 28-08-2009, 07:51 PM
  5. javascript dynamic variable name
    By Lauren Bacall in forum Software Development
    Replies: 3
    Last Post: 17-06-2009, 04:20 PM

Posting Permissions

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