SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript correct but doesn't work

    Why does my code show up with no errors in the error console yet it doesn't work! It looks all good and shows up as good yet it does not work!

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Could you post the code? Without it we can only guess what could be going wrong ...

  3. #3
    SitePoint Member
    Join Date
    May 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var flashelm = document.getElementById('blinkClass');
    var flashinter = 1000 //in milliseconds 1000/sec
    var flashcolor = "blue"

    function flashit(){

    if (flashelm.style.color == '')
    flashelm..style.color = flashcolor
    else
    flashelm.style.color = ""

    setInterval ("flashelm()", flashinter)
    }

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    1) There is a typo in this line

    Code:
    flashelm..style.color
    (two dots)

    2) Do you call the function flashit()? Why do you use a function, btw, you can just put the complete code like so
    Code:
    var flashelm = document.getElementById('blinkClass');
    var flashinter = 1000 //in milliseconds 1000/sec
    var flashcolor = "blue"
    
    if (flashelm.style.color == '')
    flashelm.style.color = flashcolor {
    } else {
    flashelm.style.color = ""
    }
    setInterval ("flashelm()", flashinter)
    just before </body> (in <script> tags of course)

  5. #5
    SitePoint Member
    Join Date
    May 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Typos are going to do me in...
    Thank you for the help!

  6. #6
    SitePoint Member
    Join Date
    May 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    flashelm.style.color = flashcolor {

    I am getting a missing; before statement error now?

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Oops, put the curly bracket on the wrong line. Should be:

    Code:
    var flashelm = document.getElementById('blinkClass');
    var flashinter = 1000; //in milliseconds 1000/sec
    var flashcolor = "blue";
    
    if (flashelm.style.color == '') {
    flashelm.style.color = flashcolor;
    } else {
    flashelm.style.color = "";
    }
    setInterval ("flashelm()", flashinter);
    Sorry!

  8. #8
    SitePoint Member
    Join Date
    May 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did try changing it but when I did that I get a message saying

    flashelm is null

    ??

  9. #9
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var flashelm = document.getElementById('blinkClass');
    var flashinter = 1000 //in milliseconds 1000/sec
    var flashcolor = "blue"
    
    if (flashelm.style.color == '')
    flashelm.style.color = flashcolor {
    } else {
    flashelm.style.color = ""
    }
    setInterval ("flashelm()", flashinter)
    If flashelm is a global function it can't be a global variable at the same time...
    Tab-indentation is a crime against humanity.

  10. #10
    SitePoint Member
    Join Date
    May 2010
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any advice of fixing it? tried a couple things but they don't work
    still a baby with Javascript!!!

  11. #11
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Your original code looks like the function has a different name. Possibly it is just the call to the function that is wrong. Perhaps the following does what you are after:

    Code:
    var flashelm = document.getElementById('blinkClass');
    var flashinter = 1000 //in milliseconds 1000/sec
    var flashcolor = "blue"
    
    function flashit(){
    
    if (flashelm.style.color == '')
    flashelm..style.color = flashcolor
    else
    flashelm.style.color = ""
    
    setInterval (flashit, flashinter)
    }
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  12. #12
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    If flashelm is null, then you don't have an element with ID "blinkClass" in your document, as document.getElementById() returns null on a non-existent ID.


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
  •