It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Script Compatibility Problem

Script Compatibility Problem

Postby lebornlion on Thu Jul 09, 2009 6:23 pm

I have Created a simple js function to search circularly in a textarea.
I have attached the js file and the html file.
When I tested this with Firefox and Chrome it works just gr8.
But with IE it fails and gives no error but invalid output.
The main functions used in the JS file Are :
Code: Select all
var thismatch=0
var last=0
var oldPhrase
var oldTextValue
function setSelectionRange(input, selectionStart, selectionEnd)
{
    if (input.setSelectionRange)
   {
        input.setSelectionRange(selectionStart, selectionEnd);
    }
    else if (input.createTextRange)
   {
        var range = input.createTextRange();
        range.collapse(true);
        range.moveEnd("character", selectionEnd);
        range.moveStart("character", selectionStart);
        range.select();
    }
    input.focus();
}

function showMatch(TXT, phrase)
{
   var lengthTrimmed=0
   if (thismatch!=0)
   {
      if(oldPhrase!=phrase && olTextValue!=TXT.value)
      {
         thismatch=0;
         oldPhrase=phrase;
         olTextValue=TXT.value;
         //alert("unequal");
      }
   }
   else
   {
      oldPhrase=phrase;
      olTextValue=TXT.value;
      thismatch=0;
   }
   thismatch++;
    var t= TXT.value;
   phrase=phrase.toUpperCase();
   t=t.toUpperCase();
   if(t.search(phrase)<0)
      return
   for(i=1;i<thismatch;i++)
   {
      if(t.search(phrase)>=0)
      {
         lengthTrimmed+=t.search(phrase)+String(phrase).length;
         t=t.slice(t.search(phrase)+String(phrase).length);
      }
   }
   if(t.search(phrase)<0)
   {
         thismatch=0
         lengthTrimmed=0
         t= TXT.value;
         t=t.toUpperCase();
         //alert("not found");
   }
   //alert(String(phrase).length+ "    " +String(t).length)
   var lp = t.search(phrase);
   //alert(t + " search=" + lp + "ThisMatch=" + thismatch)
   setSelectionRange(TXT,lp+lengthTrimmed,lp+String(phrase).length+lengthTrimmed);
}


function showMatchPrevious(TXT, phrase)
{
   var lengthTrimmed=0
   if (thismatch!=0)
   {
      if(oldPhrase!=phrase && olTextValue!=TXT.value)
      {
         thismatch=0;
         oldPhrase=phrase;
         olTextValue=TXT.value;
         //alert("unequal");
      }
      else if(thismatch>1)
      {
         thismatch--;
         thismatch--;
      }
      else
      {
         var text=TXT.value;
         thismatch=0;
         while(text.search(phrase)>=0)
         {
            text=text.slice(text.search(phrase)+String(phrase).length);
            thismatch++;
         }
         if(thismatch>0)
            thismatch--;
         //alert(" ok thismatch=" + thismatch);
      }
   }
   else
   {
      oldPhrase=phrase;
      olTextValue=TXT.value;
      thismatch=0;
   }
   thismatch++;
    var t= TXT.value;
   phrase=phrase.toUpperCase();
   t=t.toUpperCase();
   if(t.search(phrase)<0)
      return
   for(i=1;i<thismatch;i++)
   {
      if(t.search(phrase)>=0)
      {
         lengthTrimmed+=t.search(phrase)+String(phrase).length;
         t=t.slice(t.search(phrase)+String(phrase).length);
      }
   }
   if(t.search(phrase)<0)
   {
         thismatch=0
         lengthTrimmed=0
         t= TXT.value;
         t=t.toUpperCase();
         //alert("not found");
   }
   //alert(String(phrase).length+ "    " +String(t).length)
   var lp = t.search(phrase);
   //alert(t + " search=" + lp + "ThisMatch=" + thismatch)
   setSelectionRange(TXT,lp+lengthTrimmed,lp+String(phrase).length+lengthTrimmed);
}
You do not have the required permissions to view the files attached to this post.
lebornlion
 
Posts: 2
Joined: Thu Jul 09, 2009 6:10 pm

Re: Script Compatibility Problem

Postby lebornlion on Thu Jul 09, 2009 7:19 pm

OK i have pinpointed the problem.
In Internet Explorer the function search or substring account for 2 for new line characters.

To reproduce the problem add to text area

ab
ab
ab
ab
ab
ab
ab
ab

and search for ab and keep clicking next and see the error
lebornlion
 
Posts: 2
Joined: Thu Jul 09, 2009 6:10 pm


Who is online

Users browsing this forum: No registered users and 9 guests