I am developing an Editor similar to the Notepad with "Find & Replace" , "ReplaceAll" functionality.
In an HTML form I am having 3 text fields with an Editor button, when I click the Editor button it opens a pop up window with "Replace" and "ReplaceAll" buttons where I am editing the form text fields and returning back to the form.
The issue i am facing is that I am not able to do "Replace" functionality because everytime it is taking the complete string and not taking the string from where replace is done.
For ex,
if 111 is the string
then when i click "Replace" button I have to replace 1 with 12 but what is happening is like this
1 st time -- 1211
2nd time -- 12211
3r dtime -- 122211
It is not taking like this
1 st time -- 1211
2nd time -- 12121
3r dtime -- 121212
Below is the script i am using
-------------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
- // Replaces all instances of the given substring.
- String.prototype.replaceAll1 = function(strTarget, strSubString )
- {
- var strText = this;
- if(strTarget == ""||strSubString=="")
- {
- alert("Please Enter any value to replace");
- return strText;
- }
- else
- {
- var strText = this;
- var intIndexOfMatch = strText.indexOf( strTarget );
- // Keep looping while an instance of the target string
- // still exists in the string.
- while (intIndexOfMatch != -1 || intIndexOfMatch !=0 ){
- // Relace out the current instance.
- strText = strText.replace( strTarget, strSubString )
- // Get the index of any next matching substring.
- return( strText );
- intIndexOfMatch = strText.indexOf( strTarget );
- }
- }
- }
If i use bodytextrange function it works fine in IE but fails in Firefox,
Can you please point me to an article or website where i can create a script with browser compatble.
Please help me out with this script.
Thank you,