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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question document.write issue

    Im having an issue placing a document.write output in a specifc place (after my form), i want the document.write output to be produced from an if statement which is based on a variable within a function

    the document.write output is to be placed outside the script thought :S into another div

    CODE

    if (count<5) {
    document.write('unlucky')
    }

    any ideas?

  • #2
    New to the CF scene
    Join Date
    May 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    thanks

    any DOM method in particular?

    it is the calculation output from a function which i wish to base my if statement on. e.g. whether or not to say well done or unlucky

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,239
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Code:
    document.getElementById('divResults').innerHTML = "" // clear any previous message
    if (count<5) {
    document.getElementById('divResults').innerHTML = 'unlucky';  
    }

    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.

  • #4
    New to the CF scene
    Join Date
    May 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    still seems to be a problem any ideas as to where the document.getelementbyid should be placed? in a seperate function where i make the count variable global or within the orginal main function which determines the value of the count variable

  • #5
    New to the CF scene
    Join Date
    May 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question where to place statements

    var count=0;

    main function

    if (df.q1.value == answer[0])
    {
    say += "Correct\n";
    count++;
    }
    else
    {
    say += "NOT Correct\n";
    }

    if statement to display message

    document.getElementById('divResults').innerHTML = "" // clear any previous message
    if (count<5)
    {
    document.getElementById('divResults').innerHTML = 'unlucky';
    }

  • #6
    New to the CF scene
    Join Date
    May 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up my mistake

    sorry i just moved the coding around with the code u suggested and it worked perfectly thank you


  •  

    Posting Permissions

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