Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-01-2010
Member
 
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
Reply With Quote
  #2  
Old 25-01-2010
Member
 
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>
Reply With Quote
  #3  
Old 25-01-2010
Member
 
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.
Reply With Quote
  #4  
Old 25-01-2010
Member
 
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
Reply With Quote
  #5  
Old 25-01-2010
Member
 
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.
Reply With Quote
  #6  
Old 25-01-2010
Member
 
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....
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to change a variable that is saved in an object structure in JavaScript?"
Thread Thread Starter Forum Replies Last Post
Scope of Object or variable in Object oriented Programming Languages Dëfrim Software Development 3 08-01-2011 05:20 AM
How to setup a JavaScript Object Notation variable? hatred Software Development 4 04-02-2010 01:25 AM
Passing Javascript variable value into JSP scriptlet ComPaCt Software Development 3 23-09-2009 03:32 PM
Runtime Error 91 : Object Variable or with block variable not set Ryan21 Software Development 2 28-08-2009 07:51 PM
javascript dynamic variable name Lauren Bacall Software Development 3 17-06-2009 04:20 PM


All times are GMT +5.5. The time now is 08:02 PM.