Page 1 of 1

Finally get rid of <script> tags

Posted: Wed Apr 16, 2014 11:00 am
by xcislav
I'm shortening the code (onload Ø):

Code: Select all

<input onload="t=0;" onkeypress="t?e=new Date():s=new Date();t=1" onblur="d=e.getTime()-s.getTime();c=this.value.length;this.value+=c/d">
Ø

Code: Select all

<input onkeypress="t?e=new Date():s=new Date();t=1" onblur="d=e.getTime()-s.getTime();c=this.value.length;this.value+=c/d"><script>t=0;</script>


The working example is bloated with script tags. The code before that included:

Code: Select all

t==0s=new Date():e=new Date()
I was advised to exchange places s and e. And now I don't know: what's simply "t" before ternary "?" And <script>t=0;</script> must also stay in that case :(

Re: Finally get rid of <script> tags

Posted: Wed Apr 16, 2014 2:55 pm
by Christopher
It should be:

Code: Select all

// this
t==0?e=new Date():s=new Date();
// is the same as
t!=0?s=new Date():e=new Date();
// which could also be just this (if t is an integer)
t?s=new Date():e=new Date();
You might want to look at Javascript libraries like jQuery. They make binding code to events much cleaner and keep all that Javascript code out of your HTML.

Re: Finally get rid of <script> tags

Posted: Fri May 23, 2014 12:18 am
by ryancody
<input onkeyup="s?e=Date.now():s=Date.now()"onblur="c=this.value.length;this.value+=c/(e-s)"><script>s=0</script>
And if I coudn't go without global script. Tried this not working:

☑ c=this.value.length;this.value+=c/(e-s)
Ø x=this.value;c=x.length;x+=c/(e-s)

And if there's no way of shortening segment:

onkeyup="s?e=Date.now():s=Date.now()"

the upper [+ span of 20 symbols maximum] (on the cost of <scripts>)