Jump to content

xcislav

Members
  • Posts

    8
  • Joined

  • Last visited

xcislav's Achievements

Newbie

Newbie (1/7)

1

Reputation

  1. I need to cut the program to the final logic cut. It's now ~10 times smaller, although it's as far as I could get in my understanding now.Given two identical text strings. When you write in <input> you should write letters which have to be identical to the given line. And while you're typing the cursor moves until the excercise_results().My program is still big, and I need some help in understanding it's actions. I know that each text contains a final dot and a space after it. But I couldn't link this with the number "2" in for loop (after hiding the color of the <p >passage -...textDecoration "none"):length - 2[i + 2]the second:extraNodes > 2[pos + 2]and the third:(k - 1)and(k - 2) <body> <p id="isdivNode"><span>Staff. </span> </p> <form> <input size="55" onkeypress="compare(event)"> </form> <script> var strtest = "Staff. "; divNode = document.getElementById("isdivNode"); var xp = 0; deep = true; divNode.childNodes[0].style.textDecoration = "none"; for (i = 0; i < strtest.length; i++) { if (i < divNode.childNodes.length - 2) { if (divNode.childNodes[i + 2].nodeType == 1) { divNode.childNodes[i + 2].firstChild.data = strtest.charAt(i); } } else { myNode = divNode.firstChild.cloneNode(deep); myNode.firstChild.data = strtest.charAt(i); divNode.appendChild(myNode); } } extraNodes = divNode.childNodes.length - strtest.length; pos = strtest.length; while (extraNodes > 2) { divNode.childNodes[pos + 2].firstChild.data = ""; pos++; extraNodes--; } divNode.childNodes[0].style.color = "white"; document.forms[0].elements[0].value = ""; function compare(e) { var k = strtest.length; if (xp < (k - 1)) { var keyChar = String.fromCharCode(e.which); if (strtest.charAt(xp) == keyChar) { divNode.childNodes[xp + 2].style.textDecoration = "none"; xp += 1; if (xp > (k - 2)) excercise_results(); divNode.childNodes[xp + 2].style.textDecoration = "underline"; } } } function excercise_results() { confirm("fin"); } </script></body> I'm not at all experienced with DOM. It's hard for me to link conditional logic with the DOM manipulations. And I can't cut the program anymore (to have one/two "straight" conditions to see how it's work and logic) - to get the cursor just pointing to another character to match.Thanks in advance. t.php tt.php
  2. <?php$z=$_POST['l'];$db=new PDO('mysql:host=localhost;dbname=test;charset=utf8','root','hyuiuik');$db->exec("INSERT INTO AJAXTYPE (keyline) VALUES ('$z');");?> <input id="r"><div id="o"></div><div id="a"></div><script>s=0;var typetext;document.getElementById('r').addEventListener('keyup', oku);document.getElementById('r').addEventListener('blur', onbl);var j=0;function oku(){if (s){e=Date.now();typetxt=document.getElementById('r').value.substr(j);jupd();j++;}else{s=Date.now();typetxt=document.getElementById('r').value;jupd();document.getElementById('o').innerHTML="<?php echo microtime();?>";}}function onbl(){document.getElementById('r').value+=document.getElementById('r').value.length/(e-s);document.getElementById('a').textContent=typetxt;}function jupd() {var j=new XMLHttpRequest();j.open("POST", "/jpostkdb.php");j.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');j.send("l="+typetxt);} mysql> SELECT * FROM AJAXTYPE;+---------+| keyline |+---------+| s || o || b || e || r || || r || o || m || a || n |+---------+11 rows in set (0.00 sec) ~~~~~~~~~~~~~~~~| in || n || || ro || o || me || e |+---------+18 rows in set (0.00 sec) added (typed too fast) in rome
  3. I'm writing for those who will search and find mine for their use and those who have motivation for their goal. But I'm not writing for those who won't help or will advice something HOW OTHERS SHOULD BE or flame or blame or offtop.
  4. Server side. <?php $z=$_GET['l']; $db=new PDO('mysql:host=localhost; dbname=test;charset=utf8','root','hyuiuik');$db->exec("UPDATE AJAXTYPE SET keyline=concat(keyline,'$z');");?> This works. <input onkeyup="j=new XMLHttpRequest();j.open('GET', '/jpostkdb.php?l='+this.value.substr(z));j.send();z=z+1;"/><script>z=0</script> This not. <input onkeyup="if (z) {j=new XMLHttpRequest();j.open('GET', '/jpostkdb.php?l='+this.value.substr(z));j.send();z=z+1;} else z=0"/> This gives more output (the more keyup the more excessive the output is). <input onkeyup="if (typeof z === 'undefined') {z=0} else {j=new XMLHttpRequest();j.open('GET', '/jpostkdb.php?l='+this.value.substr(z));j.send();z=z+1;}"/> I could question a conclusion to the previous code +this.value.substr(z) - does not react (and this.value is creeping as is). I don't understandr if and only if statement with conditions if (z) (or if (z==0)) or if (z!==0). Yes I understand how to read them but i exchanged places of else and if several times (not operators but {ajax} and {z=0} places ... like what's the first execution). Some reasoning or even an alternative algorithm is very needed: ... <script>z=0</script> Is guaranteed to be executed the first - that's why it works fine with the global variable; Sure it shouldn't be so.
  5. Cut the code: <input onkeyup="s?e=Date.now():s=Date.now()"onblur="c=this.value.length;this.value+=c/(e-s)"><script>s=0</script> ☑ 113 <input onkeyup="s?e=Date.now():s=Date.now()"onblur="c=this.value.length;this.value+=c/(e-s)"> Ø 93
  6. plus one ("+1") "like button"-voting system I just want to have non-authorization (non-voting "system" at all - just for like button). I want to click "Like"-button key and want to have other users which visit this webpage to see this. Like-button with no additional things (no dislike) just: 1. Press - HTML/Javascript 2. Send PHP (PDO!) 3. Receive Textfile (may be.. mysql) *it has to be as simple as it could be* 4. Show +1, which would be visible to other visitors (ajax/js - optional). That example to be working. I have mysql and apache and php PDO (php5.5.6)! This is with no PDO and I don't think It could work (php5.5.6) and in any case.... The upperscript is not very much comprehensible though, because the only thing I done in PDO was: Considering the upper borrowed example ,I have some speculations: I don't need Ajax for my first steps (at all) - because it's long and lots of unknowns and after all it's increasing complexity. Might it be not a bad idea to refuse to use mysql. I had had a two-week (or so) searching(examination/looking) before js tryings when searching (in English) how to do PDO. (I should say it's a great effort to fight for your little desirable piece of code over an inet). Reminder for myself: 1. Launch mysql: /etc/init.d/mysql start just for likes: 1a) Make a db, make users, grant rights OR 1b) After mysql launch with the help of PHP/PDO: grant mysql rights admin, make a db, make db users & grant them rights to db, make tables and INSERT data INTO tables (may be a single like-table). OR even 1c) Make a textfile - and forget this brain pain and append to it (like I do it in bash >>). 2. Make HTML 2a) <form><input type=button id="likebutton" onClick="databaseinsertevent()"> 2b) ......onClick=Database insert without any functions - just because it is very many text 3. Make JavaScript 3a) something+=something+1 >>like 3b) show like on page 4. Make PHP/PDO or PHP/txt-file 4a) read last line of txt txt 1 2 3 4b) a database (much more complex variant) $db=new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', 'hyuiuik'); foreach($db->query('SELECT like FROM TABBL') as $value) { echo $value['nn']; foreach($db->query('INSERT like TO TABBL') as $something <-- #comment//* Repeat the 1st output 5. Link all modules 5a) HTML + Javascript 5b) html/js + PHP 5c) PHP/PDO + mysql (or a textfile) 5d) run /etc/init.d/apache2 start *5d1 Link apache2+mysql+php(+pdo) (emerge -av php/pdo etc...,config..) if needed ------------------------------------------------- I am in my first steps of a difficult winding climb towards ⬘
  7. It's the same (smaller and -"brain pain"): <textarea id="b" onblur="clc();"></textarea><script>t=0;x=document.getElementById('b');x.onkeypress=function(){t==0 ? s=new Date() : e=new Date();t=1;}function clc(){d = e.getTime() - s.getTime();c = b.value.length;b.value += +c+"s in "+d+"ms: "+c/d+" cpms";}</script> How the HE₺₺ does 1st work?
  8. Here's a fragment of working code with "functions inside functions". It has a "= function" definition. Here the word function is used too many times. It's a function inside a function and inside the next one. And finally the last function calls the first with all of them inside.Actually, the program has a very simple algorithm of counting typing speed:1 Starts the timer on a key-press2 Iterates every time as every next key is pressed and the stop point is in it's last key-press3 Outputs the delta in milliseconds (even without any conversion). The whole program: <script type="text/javascript"> var timing = { st: null, en: null, tx: null }; // start, end, textbox function initpr() { timing.tx = document.getElementById('prin'); var tx = timing.tx; tx.onkeypress = function () { timing.st = timing.en = new Date(); timing.tx.onkeypress = function (en) { if (!en) en = event; timing.en = new Date(); } } } function clc() { r = document.getElementById('resultpr'); deltams = timing.en.getTime() - timing.st.getTime(); chars = timing.tx.value.length; cpms = chars / deltams; snippets = [chars, " chars (in ", deltams, " ms): ", cpms, " cpms"]; r.innerHTML = snippets.join(""); initpr(); }</script><form name="foo" onsubmit="return false;"> <textarea id="prin"></textarea> <br /> <input id="btnclc" /> <span id="resultpr"></span> </form><script type="text/javascript"> document.getElementById('btnclc').onclick = clc; initpr();</script> Function initpr have additional nested functions: function initpr() { timing.tx = document.getElementById('prin'); var tx = timing.tx; tx.onkeypress = function () { timing.st = timing.en = new Date(); timing.tx.onkeypress = function (en) { if (!en) en = event; timing.en = new Date(); } } } It looks like cycle inside another one. Though it's not. Is there any possible way how to eliminate those that join?
×
×
  • Create New...