Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   Internet Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=25)
-   -   Need some Javascript help (https://www.cableforum.uk/board/showthread.php?t=24223)

Richard M 16-02-2005 17:42

Need some Javascript help
 
1 Attachment(s)
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. :confused:
It does the same in IE and Mozilla browsers... :help:

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.

philip.j.fry 16-02-2005 18:10

Re: Need some Javascript help
 
1 Attachment(s)
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.

ikthius 16-02-2005 18:19

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

Richard M 16-02-2005 19:19

Re: Need some Javascript help
 
Thanks guys. :D

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";
}


philip.j.fry 16-02-2005 19:38

Re: Need some Javascript help
 
Quote:

Originally Posted by Richard M
Thanks guys. :D

So basically I should do this?

I liked my way better (I attatched my version to the last post) :D 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.

Richard M 16-02-2005 19:45

Re: Need some Javascript help
 
Sorry I didn't even notice you attached the page. :blush:
It works now! :)
Thanks. :tu:

Richard M 22-02-2005 11:47

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. :confused:

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. :help:

philip.j.fry 22-02-2005 12:07

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

punky 22-02-2005 12:30

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.

Richard M 22-02-2005 13:56

Re: Need some Javascript help
 
Nice one! That works, thanks. :) :nworthy:


All times are GMT +1. The time now is 17:37.

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