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..!!:notworthy
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>
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.
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.
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’
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>