for loop in Macintosh Safari

Posted on 2005-05-16
Last Modified: 2008-03-03
hi folks,

I have a javascript that runs fine on firefox and IE.. no problems at all. But when I run it on safari, it looks like it takes forever or safari just hangs.. any idea how to make it work under safari as well? I'm pretty sure it is something to with the for loop because, if I reduce the number of records being pulled from the DB, the performance is better.. here is the code.. I have coldfusion query that pulls out atleast 6000 records from the DB..

The idea is that i have a text box and "name_search".. I type in something there and it will take me to the option in the 3 selec boxes to match the letters.. for eg. If I type in "S" it will take me to the option that begins with "S" in the 3 select boxes and so on..

here is the JS:

function fillin(){
            var str = document.frm.name_search.value;
            pattern = new RegExp("^"+str,"i");
            var sellength = document.frm.smart_brokerage.length;
            for(var i=0; i<sellength; i++){
                  if (pattern.test(document.frm.smart_brokerage.options[i].text)){
                        document.frm.smart_brokerage.options[i].selected = true;
            sellength = document.frm.contract_carrier.length;
            for(var i=0; i<sellength; i++){
                  if (pattern.test(document.frm.contract_carrier.options[i].text)){
                        document.frm.contract_carrier.options[i].selected = true;

            sellength = document.frm.cm_something.length;
            for(var i=0; i<sellength; i++){
                  if (pattern.test(document.frm.cm_something.options[i].text)){
                        document.frm.cm_something.options[i].selected = true;
Question by:adonis1976
    LVL 25

    Accepted Solution

    Im not sure what is about sufari... try this:
    function fillin()
    function selectIt(nm)
          var el=document.frm.elements;
          var str = el["name_search"].value;
          pattern = new RegExp("^"+str,"i");
          for(var i=0; i<el[nm].length; i++)
                if (pattern.test(el[nm].options[i].text))
                      el[nm].options[i].selected = true;
                      return i;
    LVL 11

    Author Comment

    it did the same, took forever.. i don't know what to do..
    LVL 2

    Expert Comment

    It might be a problem with your tags in the form.  Safari is much more picky than IE when it comes to id & name tags and I think with capitalization.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now