Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Need some Javascript help

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > Internet Discussion

Need some Javascript help
Reply
 
Thread Tools
Old 16-02-2005, 17:42   #1
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Need some Javascript help

I'm confused, what's supposed to happen with this page is:
You click on the "Done" link and it marks the task as done, that's fine with the first one but when you go to the next one you need to click it 2 or 3 times before it will work.
It does the same in IE and Mozilla browsers...

I've attached the entire page as .txt which you'll need to rename to .html, the javascript is being generated server-side BTW.

Thanks in advance to anyone can spot the error.
Richard M is offline   Reply With Quote
Advertisement
Old 16-02-2005, 18:10   #2
philip.j.fry
Inactive
 
philip.j.fry's Avatar
 
Join Date: Jul 2003
Posts: 1,395
philip.j.fry has reached the bronze age
philip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze age
Re: Need some Javascript help

It's the 'done' flip-flop variable, you need to have a flip-flop for each of the tasks, probably best to use an array here. Basically, when you click a done link, the value of 'done' flips over so you have to click twice the next time, once to get it back to the orignal status then again to mark as done.
philip.j.fry is offline   Reply With Quote
Old 16-02-2005, 18:19   #3
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
Re: Need some Javascript help

I may be wrong here, but your execute function takes an if else, and you are assigning 1 to 0 and 0 to 1, this may be your problem, I have noticed that even the third element of Done works the exact same, so this may show why, you are haveing this problem, thats the only thing I can see.

ik
ikthius is offline   Reply With Quote
Old 16-02-2005, 19:19   #4
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Need some Javascript help

Thanks guys.

So basically I should do this?
Code:
function execute(id) {
var taskitem = document.getElementById("taskitem_section" + id);
var msg_done = document.getElementById("msg_done" + id);
var title = document.getElementById("title" + id);
var check = document.getElementById("check" + id);
if (msg_done.style.display="none") {
	taskitem.style.opacity="0.3";
	title.style.textDecoration="line-through";
	msg_done.style.display="inline";
}
else {
	taskitem.style.opacity="1";
	title.style.textDecoration="none";
	msg_done.style.display="none";
}
Richard M is offline   Reply With Quote
Old 16-02-2005, 19:38   #5
philip.j.fry
Inactive
 
philip.j.fry's Avatar
 
Join Date: Jul 2003
Posts: 1,395
philip.j.fry has reached the bronze age
philip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze age
Re: Need some Javascript help

Quote:
Originally Posted by Richard M
Thanks guys.

So basically I should do this?
I liked my way better (I attatched my version to the last post) but yes, as long as you are checking on a per document basis it will be fine. Your way is probably less error prone though.
philip.j.fry is offline   Reply With Quote
Old 16-02-2005, 19:45   #6
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Need some Javascript help

Sorry I didn't even notice you attached the page.
It works now!
Thanks.
Richard M is offline   Reply With Quote
Old 22-02-2005, 11:47   #7
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Need some Javascript help

I need help with a related thing, I can't figure out how to pass the contents of the textarea into the script.

HTML:
Quote:
<form onsubmit="return false;"><strong>Comments:</strong><br />
<textarea rows="8" cols="30" style="width: 300px;" name="comments1" id="comments1"></textarea><br />
<input class="execute" type="submit" value="-->" name="execute" style="width: 300px; height: 30px;" onclick="post_comments(1,commentpost1); " />
Script:
Quote:
comments1 = document.getElementById("comments1");
commentpost1 = comments1.value;
function post_comments(id,text) {
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}

post_str1 = "post_comments.php?record=";
post_str2 = "&comments=";
post_str = post_str1 + id + post_str2 + text;

xmlhttp.open("POST", post_str, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var comments = document.getElementById("commentresult" + id);
comments.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null)
}
If I look at the contents of "post_str" it gives this so the comments field is not being passed to it:
post_comments.php?record=1&comments=

I'm sure there's something simple that I've overlooked.
Richard M is offline   Reply With Quote
Old 22-02-2005, 12:07   #8
philip.j.fry
Inactive
 
philip.j.fry's Avatar
 
Join Date: Jul 2003
Posts: 1,395
philip.j.fry has reached the bronze age
philip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze age
Re: Need some Javascript help

At a quick glance it looks okay, the only thing that I can suggest is:

a) Close the form tag (sorry if you have, it's just not in the section you posted).

b) Give the form a name/id
philip.j.fry is offline   Reply With Quote
Old 22-02-2005, 12:30   #9
punky
Inactive
 
Join Date: Jun 2003
Age: 44
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Need some Javascript help

Well, if you know the ID you don't need to pass the text in, it is unnesscessary. I tried to fix what you said, but getting the comments1 value outside the function makes javascript throw a hissy fit. It needs a document.getElementById around it anyway. Outside the function, it doesn't work, inside, it does. I can only see that there is a scope issue there somewhere.

I would just do:

HTML section:

Code:
onclick="post_comments(1);
And in the script section:
Code:
function post_comments(id) {

commentpost1= document.getElementById('comments' + id).value;

...
}
Try that, it should work for you. That seems to work for me anyway.
punky is offline   Reply With Quote
Old 22-02-2005, 13:56   #10
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Need some Javascript help

Nice one! That works, thanks.
Richard M is offline   Reply With Quote
Reply

Thread Tools

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 20:59.


Server: osmium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum