Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code only works if an "alert" is inline

    I have the following 2 peices of JS in my code. In the main body is:
    <select id="sboss" onChange="sb_sel_list(this.value);">
    <opt....(a bunch of <opt...s...

    function sb_sel_list (seled_sb)
    {
    var myval = 1+","+seled_sb;
    d = document.createElement("script");
    d.src = "sbsave.php?info="+myval; // stores a current ID number
    d.type = "text/javascript";
    document.body.appendChild(d);
    }

    function assign_sb(date)
    {
    var myval = date;
    e = document.createElement("script");
    e.src = "sbsched.php?info="+myval; // retreves the above ID and stores
    e.type = "text/javascript"; // ID, Date, Jobnum in the DB
    document.body.appendChild(e);
    }

    the assign only works if I "alert ("abc");" or alert (e.src); before the "document.body line. Otherwise it doesen't execute sbsched.php. A reason????? Thanks.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,048
    Thanks
    15
    Thanked 241 Times in 241 Posts
    The alert may be acting as a time delay, giving time for the data be be received from the server. This is only a very big guess. You might try inserting a setTimeout to do the same thing.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,376
    Thanks
    11
    Thanked 592 Times in 572 Posts
    you need to wait on the script to load before you make a call that needs something in the script. the easy way is to append the call to the bottom of the script file. you can also watch load/readystate events on the script tag. you can also timeout and wait for a global defined by the script file to stop ===undefined.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    New Coder
    Join Date
    Mar 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Fixed it

    (don't ask)

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,048
    Thanks
    15
    Thanked 241 Times in 241 Posts
    Quote Originally Posted by liderbug View Post
    Fixed it

    (don't ask)
    I'm asking. Someone else may need to know how you fixed it.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #6
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Hopefully not by replacing alert() with setTimeout()…

  • #7
    New Coder
    Join Date
    Mar 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    punctuation - and that's all you get

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by liderbug View Post
    punctuation - and that's all you get
    If you take that attitude you may find that in future people are unwilling to assist you again.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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