Results 1 to 2 of 2

Thread: Plz Help Me Clean Up My Script

  1. #1
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Plz Help Me Clean Up My Script

    I am pretty new to Javascript so this is some ugly code I wrote to do the purpose I desired. You can probably get the drift of the code if you look into it. I am having problems with all the timeouts because sometimes they don't happen in the right order. I was wondering if it would be better to use if/then statements to check the url of the iframes to see if they have loaded before executing next command.

    Please, Please Help me with this!

    I supposed I should explain all of this more clearly first..
    function rr= textbox and button for loading rating info of specified user in Iframe "ratingfrm"
    function manlogin= login form for yahoo users which targets a hidden iframe "loginframe". This must do several things in order:
    1.Log out of yahoo in "loginframe".
    2.Submit login form in "loginframe" Only after step 1 is finished.
    3.UNhide "loginframe" after step 2.
    4.Change url of Iframe-"ratingfrm" based on value of user on form.

    Code:
    <script type="text/javascript">
    function rr(){
    var ratename=document.rateform.ratebox.value;
    window.ratingfrm.location="http://profiles.games.yahoo.com/games/profile2?name="+ratename+"&intl=us&consolidater=spades.yahoo";}
    
    function manlogin(){
    sn=document.manlog.login.value; addy=window.ratingfrm.location="http://profiles.games.yahoo.com/games/profile2?name="+sn+"&intl=us&consolidater=spades.yahoo";
    window.loginframe.location="https://login.yahoo.com/config/login?logout=1";
    setTimeout('document.manlog.submit()',2000);
    setTimeout('hideiframe(ifrm1)',3000);
    setTimeout(addy,3000);
    }
    
    function hideiframe(element) {
        var style;
    
        if (typeof element == 'string')
          element = document.getElementById ? document.getElementById(element) : null;
        if (element && (style = element.style))
            style.display = (style.display == 'none') ? '' : 'none';
    }
    
    
    </script>
    Last edited by trippin; 02-05-2007 at 07:20 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not going to try rewriting that code so that it works. I will say that time outs are not multi-threaded. This means that while one is waiting, so are the others. In fact, sometimes when one is waiting, others will not even begin to wait. So, instead of having:

    Code:
    setTimeout('document.manlog.submit()',2000);
    setTimeout('hideiframe(ifrm1)',3000);
    setTimeout(addy,3000);
    You should probably have:

    Code:
    setTimeout('document.manlog.submit()',2000);
    Then, at the end (or possibly at the beginning) of document.manlog.submit(), have:

    Code:
    setTimeout('hideiframe(ifrm1);addy()',1000);
    This of course would require addy be made into a function.

    There could be other problems.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •