Closed Thread Icon

Topic awaiting preservation: detecting checked values (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=25602" title="Pages that link to Topic awaiting preservation: detecting checked values (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: detecting checked values <span class="small">(Page 1 of 1)</span>\

 
protoculture
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 04-25-2005 14:32

Ok, Here's my code below. I have my server side code generating these checkbox elements. And I've checked the source to make sure that the input id does equal "6". My question is why my code below is always returning false?


<input id="6" type="checkbox" name="location_id" value="someval">

<script language="javascript">

daval = document.getElementById('6').checked;
alert(daval);

</script>

www.mp3.com/protoculture

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-25-2005 14:40

The ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

To grab a form element, you can also do :

document.forms[ idOfTheForm ].elements[ nameOrIdOfElement ]


Anyway, once your checkbox have a proper ID, it should work.

Hope that helps,

protoculture
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 04-25-2005 14:52

Actually I also have some other ids named "7_text" and they seem to work fine.

I tried modifying the code by putting text in front and still the same problem. Always getting false values.

I dont understand this... it should be working. God I wish there was a proper IDE/debugger for javascript.

www.mp3.com/protoculture

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-25-2005 15:13

Once you have text in front of the id; are you *positive* that no other element on the page has the same ID?


 

protoculture
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 04-25-2005 15:17

Solved it.

It had to do with the way coldfusion was processing the code and the ourput queries.

Javascript wasn't picking up on the form values because it was placed in included templates. So I'm guessing the whole page was not yet processed when I was retireving the form values.

*duh* oh well. Thanks for the tips guys. FYI. You can start the ID of a HTML object and use it with Javascript even if you only name it as a number. eg...


<input id="6" type="checkbox" name="location_id" value="someval">
daval = document.getElementById('6').status;

www.mp3.com/protoculture

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-25-2005 15:44

if we stick to the recommendactions of the W3C, which we and the browsers vendors should/must do, an ID or a NAME attribute can NOT. If it works, it is a bug/"feature" of the browser.

HZR
Bipolar (III) Inmate

From: Cold Sweden
Insane since: Jul 2002

posted posted 04-25-2005 15:50

> You can start the ID of a HTML object and use it with
> Javascript even if you only name it as a number. eg...

That would be a markup error.

BillyRayPreachersSon
Bipolar (III) Inmate

From: London
Insane since: Jul 2004

posted posted 04-29-2005 13:44

protoculture,

Of course, you are more than free to code your IDs as numbers, and yes... it may well work for you, in the current version of the browser you use.

Don't expect it to work in all browsers, or for future versions of the browser you are using, however. Specs are there for a reason.

Dan

DmS
Maniac (V) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 04-29-2005 22:35

what's wrong with using "box_1, box_2, box_3"? that's just as easy to parse and all within the specs?
/D

{cell 260} {Blog}
-{ ?The Internet treats censorship as a malfunction and routes around it.? (-Barlow, John Perry) }-

« BackwardsOnwards »

Show Forum Drop Down Menu