Jump to content

Search the Community

Showing results for tags 'javascript'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








  1. So, I have a code that asks a question, and if the answer in correct, it says correct in the div. If incorrect, it says incorrect. For some reason it always says incorrect even if my answer is correct. Please help, is there anything wrong with this code? //*If players 1 turn if (player == "1"){ //*Asks question var trivia = prompt(questions_obj.question); //*If answer is corerct do stuff if (trivia === questions_obj.answer){ document.getElementById('correctincorrect').innerHTML = "Correct"; $('#character1').animate({left: "+=75px"}, 500, function(){ //*If player gets to finish they win if (player1total == "8"){ var winner1 = alert("Player 1 is the winner!"); $('#character1').remove(); $('#character2').remove(); $('#character3').remove(); $('#player1score').remove(); $('#player2score').remove(); $('#player3score').remove(); $('#player1header').remove(); $('#player2header').remove(); $('#player3header').remove(); $('#player1board').remove(); $('#player2board').remove(); $('#player3board').remove(); } }); //*Adds up players score player1total = player1total + 1; document.getElementById("player1score").innerHTML = player1total; } if (trivia === questions_obj.answer2){ document.getElementById('correctincorrect').innerHTML = "Correct"; $('#character1').animate({left: "+=75px"}, 500, function(){ //*If player gets to finish they win if (player1total == "8"){ document.getElementById('correctincorrect').innerHTML = "Player 1 is the winner!"; $('#character1').remove(); $('#character2').remove(); $('#character3').remove(); $('#player1score').remove(); $('#player2score').remove(); $('#player3score').remove(); $('#player1header').remove(); $('#player2header').remove(); $('#player3header').remove(); $('#player1board').remove(); $('#player2board').remove(); $('#player3board').remove(); } }); //*Adds up players score player1total = player1total + 1; document.getElementById("player1score").innerHTML = player1total; } if (trivia != questions_obj.answer || trivia != questions_obj.answer2){ document.getElementById('correctincorrect').innerHTML = "Incorrect"; }}
  2. Is it possible to have my table that loads an xml document and creates a table dynamically to store that information and create additional tags to receive information from a javascript function? Here is the code. At this moment, the only way for it to print is if the tags are manually created in the .htm file. table+=("</td></tr>");var yr = 2018;var m = 5;var d = 10;var hr = 12;var min = 12;table+=("<tr>");table+=("<td onload="countdown(yr,m,d,hr,min)"> Time Left : </td>"); table+=("<td><div id="dday"></div></td>");table+=("<td><div id="dhour"></div></td>");table+=("<td><div id="dmin"></div></td>");table+=("<td><div id="dsec"></div></td>");table+=("</tr>");table+=("<tr><td>"); the function it calls is called countdown and it displays the result using inner.html document.getElementById('dday').innerHTML=dday;document.getElementById('dhour').innerHTML=dhour;document.getElementById('dmin').innerHTML=dmin;document.getElementById('dsec').innerHTML=dsec; Please help Thank you Will this work?
  3. Yo , im building time picked with javascript and i found interessting problem , demo = http://jsfiddle.net/afo7ky03/6/ whenever you move rotating div between 2 and 3 it stops there and it shouldnt happen , i havent found any problem in scripts , did i overlooked something? thanks for answers
  4. Hello, I have a collection of html pages in hindi texts and now I want to convert those into Unicode font as per the demand. So can any one tell me the perfect javascript code that can do this task at the time of page load (without any click event). Thanks
  5. Hello, I have recently been working on a HTML form to submit new results into a search engine. However I have ran into a problem that I cant seem to get past. I have one page where the info from the form can be properly submitted, however it requires a password to get into. (its the admin panel) located at index.php?a=admin However when a user tries to insert a new site to the form the just are denied access because they cant log into the admin panel, even though the form itself is not actually in the admin panel... The HTML form looks like this and is located in a page called /AddSite.html however its trying to submit the info to /index.php?a=admin how can I use JavaScript to possibly bypass needing the password? and not redirecting to the admin panel when you click submit? (Also, not as important as the above issue... but as you can see I tried to add a capatcha, but I cant get it to be required, users can press submit without even using the capatcha... if anyone could tell me what I did wrong that would be helpful ) my current code: <form action="/index.php?a=admin" method="post"><div class=""> Site Title: <input type="text" name="addtitle" value="" required/><br /> Site URL: <input type="url" name="addurl" value="http://" required/><br /> Site Description: <br /><textarea lass="ads" name="adddesc" required></textarea><div align="center" class="g-recaptcha" data-sitekey="6LfDoAYTAAAAAOUmPcjfwv3I84xYqFBV5tyQMPJu"></div></div><br /><input type="submit" value="Add new result"/></form> Any help works!!!
  6. So I have this function that firsts asks the player, which player they are, then asks them a question. if they get it right their score increases by one, and an alert pops up that says correct. The problem is, after you answer a question, an alert pops up that says correct, and then another question pops up. No matter what your answer is nothing happens afterwards. Basically after everything happens, another question comes up but it shouldn't. Can anyone tell me if there is anything wrong with my code that might make this happen? function question(question, answer) { this.question = question; this.answer = answer;}var a = new question("What letter comes after 'a'?", "b")var b = new question("What letter comes after 'b'?", "c")var allquestions = [a, b];var player1total = 0;var player2total = 0;var player3total = 0; function ask(){ var num = Math.floor(Math.random() * allquestions.length); var questions_obj = allquestions[num]; var player = prompt("What player are you?" + " (Hint: use your player number not your name.)"); if (player = "1"){ var trivia = prompt(questions_obj.question); if (trivia === questions_obj.answer){ player1total = player1total + 1; document.getElementById("player1score").innerHTML = player1total; var correct = alert("That is correct!"); $("#character1").animate({top: "-=100px"}, 500); } else{ var incorrect = alert("That is incorrect!"); } } if (player = "2"){ var trivia = prompt(questions_obj.question); if (trivia == questions_obj.answer){ player2total = player2total + 1; document.getElementById("player2score").innerHTML = player2total; var correct = alert("That is correct!"); } else{ var incorrect = alert("That is incorrect!"); } } if (player = "3"){ var trivia = prompt(questions_obj.question); if (trivia == questions_obj.answer){ player3total = player3total + 1; document.getElementById("player3score").innerHTML = player3total; var correct = alert("That is correct!"); } else{ var incorrect = alert("That is incorrect!"); } }}
  7. Matej


    Hello , here http://jsfiddle.net/Trolstover/x9fpv8pb/3/ i have list of divs. What im trying to do , is to set scale of div which is next to div i am hovering , the code is supposed to work only on the one certain element , but is seems , that its somehow affecting all elements and breaking the code , could anyone of you help me solve this little problem?
  8. I have a problem with the jQuery AJAX Append function. Everytime I append a comment to the <span>, not only does it append that single one, but also replicates every other comment dynamically generated by the PHP. So I end up with multiple repeated comments. However, the repeated comments aren't stored in the database, so whenever I refresh the page, it goes away. How can I prevent this without refreshing the page everytime? PHP: To display all comments <span id="commentHint"></span><?phpecho "<b>$comment_user said:</b><small>$comment_time</small><br>"; echo "$comment<br>";?> AJAX: Comment On Submit <script> $(document).ready(function () { var form = $('#form'); var submit = $('#submit'); form.on('submit', function (e) { // prevent default action e.preventDefault(); // send ajax request $.ajax({ url: 'commentpost.php', type: 'POST', cache: false, data: form.serialize(), beforeSend: function () { // change submit button value text and disabled it submit.val('Submitting...').attr('disabled', 'disabled'); }, success: function (data) { var item = data; $('#commentHint').append(item); //Appends it to div. form.trigger('reset'); submit.val('Submit Comment').removeAttr('disabled'); }, error: function (e) { alert(e); } }); }); });</script>
  9. Hi I am gratefully using code at http://css3playground.com/3d-flip-cards/ to try and hold a page of twenty 300px by 300px png 'merit certificates'. I want it so when the user clicks on the bottom left corner of any certificate png (which has the words "Turn over..."), the certificate flips and the user can read the back of the certificate. I think I am almost there, it's just that not having a lot of experience with JavaScript I am not sure what changes I need to make to the code in order that it doesn't flip on mouse over but rather only when the user clicks the bottom left corner of a particular certificate on the page. From the code below, can anyone say what the Javascript would be for clicking the hotspot only? Note there could be 20+ different certificates on a page so it would need ot know which one to flip. Thanks for any help. Mark <!DOCTYPE html><html lang="en-us" dir="ltr" class="no-js"><head><link href="styles/style001.css" rel="stylesheet" type="text/css" /> <script src="javascript/jquery.min.js" type="text/javascript"></script> <script src="javascript/modernizr.min.js" type="text/javascript"></script> <title>Untitled Page</title></head><body> <form name="form1" method="post" action="default.aspx" id="form1"> <script type="text/javascript"> // For IE11. Modernizr.addTest('preserve3d', function(){return Modernizr.testAllProps('transformStyle', 'preserve-3d');}); </script> <script> $(document).ready(function(){ // set up hover panels // although this can be done without JavaScript, we've attached these events // because it causes the hover to be triggered when the element is tapped on a touch device $('.hover').hover(function(){ $(this).addClass('flip'); },function(){ $(this).removeClass('flip'); }); }); </script> <div class="hover panel"> <div class="front"> <div class="pad"> <img alt="" id="Img2" src="http://localhost:55852/LocalV/pages/files/image-store/3/2/5/3/2/5/1/1523523-ca4ead5c-ca0e-4e3b-86b8-2a42823a00e7.png" usemap="#ImageMapImageMap2" style="height: 300px; width: 300px; border-width: 0px;" /><map name="ImageMapImageMap2" id="Map1"> <area shape="rect" coords="200,260,300,300" href="" title="" alt="" /> </map> </div> </div> <div class="back"> <div class="pad"> <img alt="" id="Img1" src="http://localhost:55852/LocalV/pages/files/image-store/9/3/5/3/2/5/1/1523539-b3f8d11d-0ed8-47c4-af5e-39ad864e18a1.png" usemap="#ImageMapImageMap2" style="height: 300px; width: 300px; border-width: 0px;" /><map name="ImageMapImageMap2" id="ImageMapImageMap2"> <area shape="rect" coords="200,260,300,300" href="" title="" alt="" /> </map> </div> </div> </div> </form></body></html>
  10. Hello, I've a problem when I try to send variables (django variables) from html to javascript. My variables contain coordinates, I mean, they are decimals, and when I receive them in the javascript and I show them in console, I've got only the no decimal part of the coordinates. This is my code: Template: <td><button onclick="window.to('{{p.coorx}}','{{p.coory}}')" data-coorx="{{p.coorx}}" data-coory="{{p.coory}}">Ver Pozo</button></td> Javascript: window.to = function(coorx,coory) { var coorx = parseFloat(coorx); var coory = parseFloat(coory); console.log(coorx); console.log(coory);} I'm sure that my error is in the way in what I establish the parameters to send in HTML. I've tried several choices as: <td><button onclick="window.to(" + {{p.coorx}} + "," + {{p.coory}} + ")" data-coorx="{{p.coorx}}" data-coory="{{p.coory}}">Ver Pozo</button></td> But then it gives me an error: Uncaught SyntaxError: Unexpected token } Would anybody know how to solve this problem? Greetings and thank you very much in advance!
  11. hi to all i made a chrome extension, it works perfeclty. BUT i have a little problem and i don't know how to solve that. this is my script inside the "background.js" file: var AUTHORIZED_DOMAINS= {"siteporno.com": false,"www.siteporno.com": false};function extract_domain(url) { var matches = url.match(/^https?://([^/?#]+)(?:[/?#]|$)/i); return matches[1];} chrome.webRequest.onBeforeRequest.addListener(function(details) { var domain = extract_domain(details.url);return { cancel: AUTHORIZED_DOMAINS[domain ]===false }; }, {urls: ["<all_urls>"]},["blocking"]); My problem is this one, it block bad urls like porn websites, i have a list with some thousands urls,who are blocked. BUT when i try to block some new urls from twitter my script don't block those urls. this is the url of twitter: https://twitter.com/ and for example if i want to block "twitter.com/AlissaMaree1" my script don't work, and i need to solve that quickly. can people help me to solve that problem?? THANKS
  12. Hello, I am new to the entire field of computer software development. I am currently a police officer who is undergoing college for a degree in computer science. I have taken a great deal of interest in html and javascript and find this language to be a wonderful language to know. With that being said I am a newb when it comes to correct methods. On my time off i have spent numerous upon numerous of hours coding a javascript, html, game. The game is the classic "Don't touch the walls with your mouse" style game with a better twist. I have spent numerous hours coding in the features and intros etc.... So i only have one level currently complete. Since i am new and cannot find any similar topics to my question i thought i would ask you. My game is not built on canvas. I built it straight on html pages and then jump website pages to different aspects of the game such as level1, level 2, game over, etc.... I know I am doing this all wrong and most or all of you would be like "Don't quit your day job, This is a mess get rid of it" I would kindly request some pointers to help point in the right directions as to "fix" this game setup before i continue or perhaps some pointers on what i should be doing instead. I cannot find any other game that page jumps like mine so i assume it should not be done. Linked below is the actual game i temporarily uploaded for your viewing pleasures. If you request code let me know and i will post whichever code you would like to see. Like i said i am new and just want to do this right if i am doing this wrong. Thanks Derek http://emeraldcreations.site90.com/
  13. Hello i try make it like: <html><head> <script type="text/javascript"> function Code() { A=["T1","T2","T3",4,2,1]; var B1=A;var B2=A;var B3=A; if (A[0]=="T2") {B1[3]=5;} if (A[1]=="T2") {B2[3]=5;} if (A[2]=="T2") {B3[3]=5;} document.getElementById('W1').innerHTML="B1:"+B1[3] document.getElementById('W2').innerHTML="B2:"+B2[3]; document.getElementById('W3').innerHTML="B3:"+B3[3]; } </script></head><body> <input type="button" value="Code it!" onClick="Code()"><br><br><br> <div id="W1"></div> <div id="W2"></div> <div id="W3"></div> </body> when i press button then i got 5 on all B1, B2 and B3. but it should be only B2 have 5 while other got 4. Why it going wrong?
  14. Has anyone seen an intermittent buttons missing styling on a page before when in the enabled="false" state? I have a page that shows the buttons correctly in ie11 using win8 but on a desktop win7 ie11 does not show the buttons. They appear as text and when the checkbox is clicked triggers an onClick which enables the buttons okay. For some reason they are not styling intermittently. I don't believe its the client side script preventing it from appearing since it doesn't happen all the time and there doesn't seem to be a pattern or I haven't found one yet. Is there a setting in IIS that might be causing the problem? Someone was just working on the servers making adjustments and I received a windows security prompt which I've never seen before, but that's the test server. Live server is okay, but the buttons are a problem. Has anyone experienced this issue?
  15. Hi everybody!Im newbie to php. please,suppose we have a MYSQL DATABASE with table CUSTOMERS.In the page: addCustomer.php, we echoed this table and it returned us a number of rows.on the same page, we have a form that contains empty fields. (name, birth, adress).Questions:How to add a button front of each displayed row? and how to when we click on the related button we fill the content of the form and submit it to the table CUSTOMERS. we want to verify if the customer exists when echoing...if so we click on the relative row, and the form is filled. if no we fill the form manually thanks <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css"><!--.style2 {font-size: 36px}.style4 {font-size: 24px}#hauttableau { background-color:black; color:white; text-align:center; padding:5px;}--></style><script language="JavaScript" type="text/JavaScript"><!--function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();}MM_reloadPage(true);//--></script></head><body><p align="left" class="style2">NOUVEAU CLIENT </p><form name="form1" method="post" action="insert_pdo_ajout_client.php"> <p class="style4"></p> <p><span class="style4">CLIENT</span> </p> <p> NOM CLIENT<input name="nomclientField" type="text" id="nomclientField"> <p> PRENOM <input name="prenomclientField" type="text" id="prenomclientField"> <p>ADRESSE <input name="adresseclientField" type="text" id="adresseclientField"></p> <p>DATE NAISSANCE <input name="datedenaissanceField" type="text" id="datedenaissanceField"></p> <p> CIN <input name="cinclientField" type="text" id="cinclientField"> </p> <p>TEL <input name="telclientField" type="text" id="telclientField2"> </p> <p> <input type="submit" name="Submit" value="ENREGISTRER"> </p></form><p class="style2"> </p><?phpecho "<table style='border: solid 2px black;' class= 'hauttableau'>"; echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th></tr>";class TableRows extends RecursiveIteratorIterator { function __construct($it) { parent::__construct($it, self::LEAVES_ONLY); } function current() { return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>"; } function beginChildren() { echo "<tr>"; } function endChildren() { echo "</tr>" . "n"; }}$servername = "localhost";$username = "root";$password = "root";$dbname = "zg";try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("SELECT idclient, nomclient,prenomclient,datedenaissanceclient,adresseclient, cinclient,telclient FROM client"); $stmt->execute(); // set the resulting array to associative $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { echo $v; }}catch(PDOException $e) { echo "Error: " . $e->getMessage();}$conn = null;echo "</table>";?> </body></html>
  16. Hi, I am fairly new to javascript and still finding my feet so if i am not been clear in my question let me know. I am using the chart.js to build graphs in my docuemnts and it works great, I am now trying to expand this by linking to an xml file I have set up. If I use the following code I can retrieve the data fine: xmlDoc=loadXMLDoc("rego.xml");var nSubOrg = xmlDoc.getElementsByTagName('SubOrg');var nRev = xmlDoc.getElementsByTagName('Revenue');var nCol = xmlDoc.getElementsByTagName('Colour');var nHL = xmlDoc.getElementsByTagName('HLight'); //chart data for Chart.JS var dData = [ { value: (nRev[0].childNodes[0].nodeValue), color: (nCol[0].childNodes[0].nodeValue), highlight: (nHL[0].childNodes[0].nodeValue), label: (nSubOrg[0].childNodes[0].nodeValue) }, { value: (nRev[1].childNodes[0].nodeValue), color: (nCol[1].childNodes[0].nodeValue), highlight: (nHL[1].childNodes[0].nodeValue), label: (nSubOrg[1].childNodes[0].nodeValue) }, { value: (nRev[2].childNodes[0].nodeValue), color: (nCol[2].childNodes[0].nodeValue), highlight: (nHL[2].childNodes[0].nodeValue), label: (nSubOrg[2].childNodes[0].nodeValue) }]; However I am trying to make this a bit more functional so want to loop through to create the multidimension array. I have found other snippets which gve me an idea about how to do this but I just can't get it work. I think something like this should but can't get my head round the exact syntax: xmlDoc=loadXMLDoc("rego.xml");var nSubOrg = xmlDoc.getElementsByTagName('SubOrg');var nRev = xmlDoc.getElementsByTagName('Revenue');var nCol = xmlDoc.getElementsByTagName('Colour');var nHL = xmlDoc.getElementsByTagName('HLight');//try and build arrayvar dData=new array[()]for (i=0; i<nRev.length; i++) { dData[i].push( value: (nRev[i].childNodes[0].nodeValue), color: (nCol[i].childNodes[0].nodeValue), highlight: (nHL[i].childNodes[0].nodeValue), label: (nSubOrg[i].childNodes[0].nodeValue) ); }; Any help would be appreciated. Cheers Soggy
  17. Alright, so I am making a program that when a button that says "yo" for example, will display a prompt when click. If the answer to the prompt is a verb, then the "yo" form of that verb is displayed. So far I have a button, that when clicked has a prompt. When I enter a word in the button I can't make it display the "yo" form of the verb. Please help: Here is my javascript: function verb(verb, yo) { this.verb = verb; this.yo = yo;}//*All verbsvar estar = new verb("estar", "estoy");//*All arraysvar verbs = [estar];//*Verb translation present_yofunction presentYo(){ var verb = verbs; var answer = prompt("Enter a verb: ").toLowerCase(); if (answer == verb){ document.getElementById("translation").innerHTML = "verbs.yo"; } else{ document.getElementById("translation").innerHTML = "I do not know the translation."; } } When I enter a word, all that shows up is "I do not know the translation." Please help. Thanks.
  18. On my website I have some hide/show java script (below). It is used commonly in FAQs where you see a list of questions and when rolling over the question it changes color and clicking on it opens text. I would like the cursor to change to a "finger pointer" ( the usual shape of when something is linked) when rolling over the text. Does anyone know how to do that? What should be added to the coding below? The words MY TEXT represent the various text I put in specific to my site. Thank you! (I'm extremely new to all of this ) <a onclick="javascript:ShowHide('item')"> MY TEXT </a> <div class="mid" id="item" style="display: none;"><p> MY TEXT </p></div> <br> <script type="text/javascript">// <![CDATA[ function ShowHide(divId) { if(document.getElementById(divId).style.display == 'none') { document.getElementById(divId).style.display='block'; } else { document.getElementById(divId).style.display = 'none'; } } // ]]></script>
  19. Hello, I have been developing a website for a school project in html, css and javascript. We'll be using the website for an interactive board game. One of the most important elements of the website are the scoreboard and the game questions. The game questions basically give a specific amount of points if correctly answered. The points will then be sent to the scoreboard, and saves it. The scoreboard makes use of cookies to save the data/reset the data. And here comes my problem.. the scoreboard works great in Internet Explorer and Firefox, but not in Google Chrome. I have followed a tutorial on how to use cookies on w3schools (http://www.w3schools.com/js/js_cookies.asp) to help create the scoreboard. The cookies apparently do not work for me when I use Google Chrome, which is very unfortunate. I would really like the website and cookies to be cross-browser compatible, and therefore I need some help. If anyone could help me out, then that would be great! These are my scripts: index.html <!doctype html><html lang=nl><head> <meta charset=utf-8> <script src="cookie.js"></script> </head><!-- dit is jouw hoofdpagina. zie ook commentaar op pag2.html Script toevoegen op al je pagina's bij je hoofdpagina bij de body onload=checkScore() toevoegen--><body onload=checkScore()> <a href=pag2.html>Klik hier voor 10 punten</a><br> <a href=pag3.html>Klik hier voor 5 punten</a> <!-- deze div moet toegevoegd worden op de plek waar je de score wilt zien --> <div id=score> </div> <!-- button om de scores op nul te zetten --> <button onclick="reset()">Reset</button></body></html> pag2.html <!doctype html><html lang=nl><head> <meta charset=utf-8> <script src="cookie.js"></script> <script> var erbij=10; function terug() { createCookie("erbij", erbij); window.location.assign("index.html"); } </script></head><body> <button onclick="terug()">Terug</button> <button onclick="erbij=erbij+1">punten</button></body></html> pag3.html <!doctype html><html lang=nl><head> <meta charset=utf-8> <script src="cookie.js"></script> <script> var erbij=5; function terug() { createCookie("erbij", erbij); //window.history.back(); window.location.assign("index.html"); } </script></head><body> <button onclick="terug()">Terug</button></body></html> cookies.js function checkScore() { var s=getCookie("score"); if (s != "") { erbij=getCookie("erbij"); if (erbij == "") { erbij="0"; } score= (parseInt(s)+parseInt(erbij)).toString(); createCookie("score", score); } else { score="0"; createCookie("score", score); erbij="0"; createCookie("erbij", erbij); } document.getElementById("score").innerHTML="Score: "+score; } function createCookie(name, value, days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } else { expires = ""; } var t=name + "=" + value + expires + "; path=/"; document.cookie = name + "=" + value + expires + "; path=/"; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1); if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function eraseCookie(name) { createCookie(name,"",-1); } function reset() { document.getElementById("score").innerHTML="Score: 0"; eraseCookie("score"); eraseCookie("erbij"); } All I need is the cookies to work in Google Chrome. Thanks in advance, Es_Dexter
  20. I have been trying to write a photo gallery with text accompanying it at the bottom. Photos and text will change with each click. I tried using an input tag as child of form tag with javascript code and it worked. But the input tag is interactive and allows only one line. By the way, it doesn't respect the <a> tag for crediting the photos. Therefore, I have been trying my hands on the figure element which will take the image tag and figcaption tag for photo and photo description. But, I cannot write the javascript. can anyone show me how? I wonder why the input tag is easy but figure and figcaption is difficult? Thanks
  21. Hey, so I have a code where you click a button, it tells you to translate a word, then tells you if you are correct or incorrect. I am adding something so that when you get a word correct, it goes on the left side, when you get a word wrong, it goes on the left side. My code works, aside from one thing. When you get a word right, it lists it on the left side, but the next word replaces the previous word. Here is one of my functions: function spanishLocation(){ var num = Math.floor(Math.random() * locations.length); var locations_obj = locations[num]; var answer = prompt("Translate: " + locations_obj.spanish).toLowerCase(); if (answer == locations_obj.english){ document.getElementById("icorrect").innerHTML = "Correct"; document.getElementById("AddCorrect").innerHTML = locations_obj.spanish + ": " + locations_obj.english; document.getElementById("CorrectAnswer").innerHTML = ""; } else{ document.getElementById("icorrect").innerHTML = "Incorrect"; document.getElementById("CorrectAnswer").innerHTML = locations_obj.english; } } How do I change the document.getElementById("AddCorrect").innerHTML = locations_obj.spanish + ": " + locations_obj.english; so that it adds the word and its translation to a div, rather than replacing it? Does that make sense?
  22. Hey, so I have a question regarding my previous post. I am trying to randomly change the color of a div just by ppressing it. Here is my code to do so: My html: <button onclick="changeShirtColorRandom()">Change Shirt Color Random</button> My javascript: function color(color){ this.color = color;}//*All colorsvar red = new color("red");var blue = new color("blue");var green = new color("green");var purple = new color("purple");var yellow= new color("yellow");var black = new color("black");//*Array of colorsvar colors = [red, blue, green, purple, yellow, black]; //*Function that chooses a random shirt colorfunction changeShirtColorRandom{ var num = Math.floor(Math.random() * colors.length); var colors_obj = "'" + colors[num] + "'"; document.getElementById("torsoColorChange").style.backgroundColor = colors_obj; document.getElementById("right-sleeveColorChange").style.backgroundColor = colors_obj; document.getElementById("left-sleeveColorChange").style.backgroundColor = colors_obj;} This is just the part of the code that is relevant. The problem is when I click the button nothing happens. What is wrong with my code?
  • Create New...