|
|
 |
Re: FN-FORUM: Check box problem
date posted 19th March 2008 11:06
On March 19, 2008 11:55 AM, Pam wrote:
>
> Strange isn't it
>
> This is the Check box
>
>
> diaries?" Text="All Diary's">
>
>
> This is the bit of code
>
>
> function Check_Diary_Validate(source, arguments) {
> arguments.IsValid = false
> if (document.getElementById("ALL_Diaries") !== null) {
> if (document.getElementById("ALL_Diaries").Checked == true) {
> arguments.IsValid = true
> }
> }
>
> This bit works
>
> if (document.getElementById("ALL_Diaries").Checked == true
>
> But is doesn't get passed
>
> if (document.getElementById("ALL_Diaries") !== null) {
>
> because document.getElementById("ALL_Diaries") is null
>
>
>
> Pam
The asp.net code is:
but what does the code on the client look like? That is especially
important when you're using master pages and / or grouping checkboxes or
radio buttons.
When creating a group of radio buttons or check boxes, I think asp.net by
default creates a table with an id="All_Diaries". Inside the table it
creates, for each row, the individual checkbox elements with ids like
id="All_Diaries0", "All_Diaries1", etc.
The lesson to be learned is:
1) When using javascript with asp.net controls always 'view-source' of your
html.
2) Don't use the default asp.net controls. Use the css-friendly ones.
Css-friendly controls are a breeze to install and much easier to work with
if you're looking for consistent cross-browser display results.
PS: The link James explained it. In general, with javascript, always create
the element first with:
var x = document.getElementById('blah');
The id used by asp.net and the client are only the same, in the browser
source, sometimes. Often times they are different.
In the example above, to get the actual id as seen by the browser, it would
usually be done like this:
var x = document.getElementById('');
Then do something with it:
if(x) {// code which does somethign to x}
Don't do this:
document.getElementById('blah').style.display = 'none';
Or stuff like that because. 1) you don't know whether it's there and 2)
sometimes you can't change the properties like that anyway.
|
 |
|