Some basic basic stuff

1 view
Skip to first unread message

Eugene Hourany

unread,
Nov 5, 2009, 8:25:30 PM11/5/09
to prototype-s...@googlegroups.com
Hi all,

I'm tearing my hair out trying to figure out why I keep getting a "element is null" error. Here's what my code looks like:

$('firstname').hide();

and I have

<input id="firstname" name="firstname" value="" />

and I get

Error: $("firstname") is null
Source File: file:///C:/Documents%20and%20Settings/142253/Desktop/test/index.html#
Line: 14

I'm doing this locally from my desktop. I'm using prototype 1.6.1.

I also would like to know how to open a json file for reading and parse it.

Thanks!

Eugene

T.J. Crowder

unread,
Nov 6, 2009, 8:47:02 AM11/6/09
to Prototype & script.aculo.us
Hi,

It sounds like you're not succeeding in loading Prototype or something
else you're loading is conflicting with it, I suggest checking your
script tags. The code you've quoted and the HTML you've quoted should
work, provided Prototype is getting loaded.

FWIW,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

bill

unread,
Nov 7, 2009, 2:49:46 PM11/7/09
to prototype-s...@googlegroups.com
Eugene Hourany wrote:
Hi all,

I'm tearing my hair out trying to figure out why I keep getting a "element is null" error. Here's what my code looks like:

$('firstname').hide();

and I have

<input id="firstname" name="firstname" value="" />

and I get

Error: $("firstname") is null
Source File: file:///C:/Documents%20and%20Settings/142253/Desktop/test/index.html#
Line: 14

I'm doing this locally from my desktop. I'm using prototype 1.6.1.

do you have the input declaration before the execution of the "$('firstname').hide();"

If you execute the js before the input is declared, the id will not exist.

bill


-- 
Bill Drescher
william {at} TechServSys {dot} com

kstubs

unread,
Nov 7, 2009, 4:45:13 PM11/7/09
to Prototype & script.aculo.us
Try naming the ID attribute different than the NAME attribute.

Eugene Hourany

unread,
Nov 9, 2009, 2:04:25 AM11/9/09
to prototype-s...@googlegroups.com
I never put in a name attribute, that could be part of the problem.

I solved it by putting it in a function that's called by onclick, and it worked. I was able to reference it the old fashioned JS way, and prototype's way.

Now all I want to know is how to load and parse a JSON file using the same method.

Thanks!

Eugene

Alex McAuley

unread,
Nov 9, 2009, 2:35:30 AM11/9/09
to prototype-s...@googlegroups.com
Its happening because (as someone pointed out in a previous reply) the DOM node does not exist yet .....
 
you need to wrap the code in observers...
 
for example...
 
Event.observe(window,'load',function() {
 
    $('TheElementToHideObserver').observe('click',function() {
    $('firstname').hide();
 
 
});
});
 
//Then your html
 
 
<input type="submit" id="TheElementToHideObserver" value="Hide First Name" />
<hr />
<input type="text" name="firstname" id="firstname" />
 
 
....
 
Simple as that
 
HTH
 
 

ColinFine

unread,
Nov 9, 2009, 8:34:41 AM11/9/09
to Prototype & script.aculo.us


On Nov 7, 9:45 pm, kstubs <kst...@gmail.com> wrote:
> Try naming the ID attribute different than the NAME attribute.
>

What difference would that make?

However, what I was going to suggest was checking that your id
'firstname' is unique in the page. Names can be duplicated, but id's
can't.

ColinFine

unread,
Nov 9, 2009, 8:57:29 AM11/9/09
to Prototype & script.aculo.us


On Nov 9, 7:04 am, Eugene Hourany <ehour...@gmail.com> wrote:
> I never put in a name attribute, that could be part of the problem.
>
No.
>
> Now all I want to know is how to load and parse a JSON file using the same
> method.

What's a JSON file?

JSON is a text representation of data which is pretty well identical
to Javascript's own notation, so you can parse it with eval().
However, if the JSON is coming from Ajax, it's already available to
you as a parsed object: see http://www.prototypejs.org/api/ajax/response
Reply all
Reply to author
Forward
0 new messages