[Javascript] Retaining values

tedd tedd at sperling.com
Sat Apr 16 08:26:39 CDT 2011


At 3:16 PM +0000 4/15/11, Troy III Ajnej wrote:
>Hey Tedd, good work. Yet
>seeing this, makes me wonder...
>
>---------------------- 8< -------------------
>function checkJS()
>{
>/* if javascript is ON, then make javascript stuff visable
>else all javascript stuff is hidden (i.e., display: none) */
>
>document.getElementById('js').style.display = "block";
>}
>---------------------- >8 -------------------
>
>thankfully it isn't working.
>
>What is this code supposed to do,
>cause we don't want people to see our loundry,
>do we?

I believe it *IS* working -- at least it works when I test it. Try 
turning JavaScript OFF and reload the form -- I don't think you'll 
see the "Add Another Record"button -- do you?

You asked:

>What is this code supposed to do?

I created this technique, so I think it's clever, but I have not had 
peer review.

So, I'll explain --

The JavaScript that makes this form work, namely:

http://webbytedd.com/aa/add-text-field/index.php

is triggered by the html statement:

<input type="button" id="js" onclick="addInput()" value="Add Another Record">

However, when a user first visits the page, CSS has this statement 
set to "display: none" via the CSS rule:

#js
   {
   display: none;
   }

So, the user doesn't see the control.

However, if the user has JavaScript turned ON, then the JavaScript statement:

document.getElementById('js').style.display = "block";

turns the style of this statement to be "block" so the user will see 
the statement.

This is just a simple way to test if JavaScript is enabled. If it is 
then the JavaScript specific controls are shown, if not then they are 
hidden.

Understand?

Again, I am open for comment.

Cheers,

tedd



-- 
-------
http://sperling.com/


More information about the Javascript mailing list