Jump to content

sugafree

Members
  • Posts

    50
  • Joined

  • Last visited

Everything posted by sugafree

  1. Sorry, it was saved as xhtml, soon as I changed to to html it works fine. Thanks again
  2. The error message is not well-formed and pointing this line. Tried it with mozilla, that one said not well-formed. IE not displaying anything.
  3. Thanks Davej. I tried it but it wasnt working. In the function setCookie, it says this line is not well-formed if (cookie_name!=null && cookie_name!="" && cookie_val!=null && cookie_val!=""){
  4. So mine wasnt even close:( Im gonna look into target event stuff now...thanks
  5. It says tname.style is undefined. Is the background-color bit wrong?
  6. Ok this is not working yet..but I hope I am on the right track. I am stuck with it a bit. Not sure if I should use setProperty or setAttribute also dont know how to call that properly and cant find many examples I could use. If thats correct, I think it should work, although I worked my way around and tname=targ.tagName; should be something like tname=targ.tagId but again couldnt find how to call id instead of tagname. Tried tagid, tagId, Id but I think still could only get the tagname. What do you think? <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>HTML</title><script>function whichElement(e){var targ;if (!e) { var e=window.event; }if (e.target) { targ=e.target; }else if (e.srcElement) { targ=e.srcElement; }var tname;tname=targ.tagName;tname.style.setProperty("background-color: grey;");//alert("You clicked on a " + tname + " element.");} /*var e=window.event;e.target=var target=document.getElementById().target;("background-color", "grey"); } */ </script></head> <body onmousedown="whichElement(event)"><div id="contentWrapper" style="width: 1000px; margin: auto;"><div id="leftSidebar" style="width: 200px; height: 200px; background-color: red; float: left; margin: 12px 20px;">left</div> <div id="middle" style="width: 200px; height: 200px; background-color: red; float: left; margin: 12px 20px;">middle</div><p id="right" style="width: 200px; height: 200px; background-color: red; float: left; margin: 12px 20px;">right</p></div></body>
  7. onmousedown= and give the function to create a new node?? Is that what I meant to figure out? Anyway its a good idea, but would it automatically store the coordinates and I would need to put it together? I only few a few more days to finish this, and if I would have to use both, I would rather create empty div's on the page and set the id's in html, also this onmousedown would be a lot easier as well I guess. The problem with this is I would have limited number of divs only
  8. Ok i would use <body onmousedown="...()"> In that function first I would need a var x= getElementById, assuming everything has an id, after I would need to find the code for set.backgroundcolor of var x to grey. Am I really far from reality?
  9. or could I just refresh a specific div in the body? that case I put that in a div and.... dont know the rest but at least Ive got an idea:)
  10. This wont work either. Could I set the interval for the function which displays the number? var delay = 500;var expDays = 30;var exp = new Date();exp.setTime(exp.getTime() + (expDays*24*60*60*1000));function amt(){var count = GetCookie('count')if(count == null) {SetCookie('count','1')return 1setInterval(amt,delay);} <body><script LANGUAGE="JavaScript"><!-- Begindocument.write("You have visited this page for <b>" + amt() + " times.")// End --></script><input type="button" onclick="DeleteCookie('count')" value="Delete Cookies"/>
  11. Could i use the amt() function to force itself to always refresh and that might solve this problem if it wouldnt crash the page. Is that a really bad idea?
  12. Its still not working. I tried it a few different ways with reload() and every time the browser starts refreshing itself and just wont stop and wont display anything on the page.
  13. function should I use? Sorry went wrong even with copy and paste..
  14. also tried the reload in the DeleteCookie function, didnt work either. What I need to accomplish is when you click delete cookies, a confirmation window appears and if ok clicked the hit counter should display 1 without having to refresh the page. If I run this code it wont do it. What sort of functi
  15. Ive tried function DeleteCookie (name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString() + restart();}function restart () {window.location.reload;}
  16. Im back. I have got a few ideas, but I dont want to sound like an absolute joke. Im going to read again the js tutorial and I will try to come up with something soon.
  17. Im sorry I dont understand it at all. I thought the parent element is div1 and also dont understand why is the parent element so important. Is that going to be used to select the nodes to be deleted? To start with the basic version, without the XY coordinates, what would you say is the best or good and easy option to be able to select which ones to delete. Checkbox created with the new nodes? Thanks
  18. Hi, I am trying to amend a cookie script. I have found this online and when I hit the delete cookies button, I have to refresh the page to see it. How could I do this as the deleteCookie function is resetting the exp time which does it but what do I need to add afterwards to make it refresh automatically? after document.cookie = line function DeleteCookie (name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); <--} i tried location.reload(); and window.reload(); but wasnt working. Any idea? Here is the full code <script LANGUAGE="JavaScript">function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) {var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null;}function SetCookie (name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");}function DeleteCookie (name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); var cval = GetCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();window.reload();}var expDays = 30;var exp = new Date();exp.setTime(exp.getTime() + (expDays*24*60*60*1000));function amt(){var count = GetCookie('count')if(count == null) {SetCookie('count','1')return 1}else {var newcount = parseInt(count) + 1;DeleteCookie('count')SetCookie('count',newcount,exp)return count }}function getCookieVal(offset) {var endstr = document.cookie.indexOf (";", offset);if (endstr == -1)endstr = document.cookie.length;return unescape(document.cookie.substring(offset, endstr));}// End --></script></head> <body><script LANGUAGE="JavaScript"><!-- Begindocument.write("You have visited this page for <b>" + amt() + " times.")// End --></script><input type="button" onclick="DeleteCookie('count')" value="Delete Cookies"/> </body> Thanks
  19. I dont need to store these comments anywhere, I only have to do the javascript bit of it so if I close the page and it will all disappear it doesnt matter. X-Y coordinates for the question 'where to put' is not a bad idea, but I will still need a unique id or name to each new node. Also with a unique id, might be easier to create just a dropdown menu to select which one to delete or the checkbox automatically added to nodes and then a delete button with a function to delete all checked nodes? Is that a bad idea? for the unique id var node=document.createTextNode(inputText); node.setAttribute("id", "p + ([i++)") or something.. and then set a loop for i. would this work?
  20. Depends which one:) I did "study" it for a while. I dont understand the for loop and why we have the preload or what is it doing, if the rotateimage function is to return the random number. Also within the rotateimage function the do while loop is not what I would say I completely understand, but I know if the random number is the same as the one which is currently displayed, then it will run it again until ...right? Its hard to put it all together, but the more I see, the more I learn. I am trying
  21. Hi, I am trying to create a text tag where users can add comments, delete them and also choose where to insert that comment(if not default). My problem is how to give each new node a unique id, which should be a number 1, 2 and so on. Using these numbers, the user could select where to insert the new par or even to select which one to be deleted. To be honest I want to create a checkbox next to the new par, so the user can just thick which par to delete and then press the button, but I am open to better ideas:) For start could someone help me how to make it a create a unique id for each new nodes and how to call 2 var inside appendChild() Thanks <script> function addNew(){ var inputText=form.inputText.value var para=document.createElement("p"); var node=document.createTextNode(inputText); var x = document.createElement("INPUT"); x.setAttribute("type", "checkbox"); para.appendChild(node); // I tried para.appendChild(node, x); var element=document.getElementById("div1"); element.appendChild(para); // also element.appendChild(para, x); and all other variations. } function deleteComment(){ var parent=document.getElementById("div1"); var child=document.getElementById("ggg"); parent.removeChild(child); } /* * function addBefore(){ var inputText=form.inputText.value var para=document.createElement("p"); var node=document.createTextNode(inputText); para.appendChild(node); var element=document.getElementById("div1"); var child=document.getElementById("line"); element.insertBefore(para,child); } * */ </script> </head> <body> <form id="form"> <input type="text" value="inputText" id="inputText" /> <input type="button" value="Add New Comment" onclick="addNew()" /> <input type="button" value="Delete A Comment" onclick="deleteComment()" /> </form> <div id="div1"> <p id="ggg">gggggg</p> </div> </body>
  22. Oh my days...Davej it is working.... just had to rename the pics. THank YOU!! Sorted
  23. First of all guys, I would like to thank you for being patient with me:) I am getting there but I only started javascript and it is not easy. The code Davej gave me is pretty close to what I need and also I will look up the links in the last comment because I want to learn JS. Only problem with that link is that it does not show the random images. Sometimes it shows the alt text which is random images, sometimes a pic etc.. Anyway in a few hours I will look into it and try to sort it out myself before asking for more help. Btw after this is done, I still have more stuff to sort out like cookies and puzzle etc, so I wouldnt want to use all my "freebies" on this...justs kidding. Thanks for your help again guys
  24. I have just recently started javascript and still could not get it work. changediv function was just a mistake, it meant to be getDiv function. I have change a few things but ran into problems again. function getDiv () { document.getElementTagName("img")[0].innerHTMl=newimages(); // for this line it says its not a function } var newimages= function (){ randomimages[Math.floor(Math.random()*(randomimages.length))] // also i am gessing this is not the proper way to display the images but i havent got a clue }; for document.images.splash should i put the images in a document instead of var randomimages? or what should i put there? Also i was thinking of changing the whole function rotateimage but any other i have found did not have a delay in it.
  25. Hi, I need to use getElementById to reference to a div which contains a pic and without changing anything in the body tag, a random image slideshow should appear on load! instead of that pic. I have tried different ways to sort it out, but it was never perfect... Got 3 problems, first function changeDiv it says getElementsByTagname(...)[] is not defined... second is in the function rotateimage else document.images.splash undefined... third newimages function overwrites the whole page and it should only change the div anyone could help me out on this one?? Thanks 1.html
×
×
  • Create New...