Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 12:03 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ]  Bookmark and Share
Author Message
 Post subject: Script Compatibility Problem
PostPosted: Thu Jul 09, 2009 7:23 pm 
Offline

Joined: Thu Jul 09, 2009 7:10 pm
Posts: 2
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:
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);
}


Attachments:
js.zip [1.5 KiB]
Downloaded 9 times
Top
 Profile  
 
 Post subject: Re: Script Compatibility Problem
PostPosted: Thu Jul 09, 2009 8:19 pm 
Offline

Joined: Thu Jul 09, 2009 7:10 pm
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley