Finally get rid of <script> tags

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
xcislav
Forum Newbie
Posts: 4
Joined: Fri Apr 11, 2014 9:00 am

Finally get rid of <script> tags

Post 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 :(
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Finally get rid of <script> tags

Post 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.
(#10850)
ryancody
Forum Newbie
Posts: 14
Joined: Wed May 21, 2014 1:48 am

Re: Finally get rid of <script> tags

Post 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>)
Post Reply