Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-11-2012, 01:15 AM   PM User | #1
bgnerr
New to the CF scene

 
Join Date: May 2012
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
bgnerr is an unknown quantity at this point
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?
bgnerr is offline   Reply With Quote
Old 05-11-2012, 01:35 AM   PM User | #2
bgnerr
New to the CF scene

 
Join Date: May 2012
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
bgnerr is an unknown quantity at this point
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
bgnerr is offline   Reply With Quote
Old 05-11-2012, 07:59 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 05-11-2012, 11:01 AM   PM User | #4
bgnerr
New to the CF scene

 
Join Date: May 2012
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
bgnerr is an unknown quantity at this point
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
bgnerr is offline   Reply With Quote
Old 05-11-2012, 11:33 AM   PM User | #5
bgnerr
New to the CF scene

 
Join Date: May 2012
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
bgnerr is an unknown quantity at this point
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';
}
bgnerr is offline   Reply With Quote
Old 05-11-2012, 11:59 AM   PM User | #6
bgnerr
New to the CF scene

 
Join Date: May 2012
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
bgnerr is an unknown quantity at this point
Thumbs up my mistake

sorry i just moved the coding around with the code u suggested and it worked perfectly thank you
bgnerr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:25 AM.


Advertisement
Log in to turn off these ads.