Firefox and getElementById

Discussion in 'Javascript' started by jason.hau@gmail.com, Sep 25, 2006.

  1. Guest

    Ok, interesting problem here, I have a webcontrol that holds a textbox
    and a requiredfieldvalidator from System.Web.UI.Webcontrols in .NET 2.0
    (this is javascript related, bear with me).
    The validator is added to the page validator collection so at run time,
    ..NET auto generates an array e.g.:
    var Page_Validators = new
    Array(document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl1"),
    document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl3"));
    which it then references as part of the client side validation.
    For some reason however, this works perfectly in IE, works fine in my
    test harness but doesn't work in the release project. The ONLY possible
    reason that I can see is that the release project has underscores in
    the ID and my test harness does not.
    Has anyone come across this before?
    Please note 2 things:
    1) The id attribute is auto-generated by .NET and thus I have extremely
    limited control over altering it.
    2) The array Page_Validators is auto-generated as well and I have
    absolutely NO entry point with which to alter it so I CANNOT change the
    method of .getElementById, etc.
     
    , Sep 25, 2006
    #1
    1. Advertising

  2. wrote:


    > The validator is added to the page validator collection so at run time,
    > .NET auto generates an array e.g.:
    > var Page_Validators = new
    > Array(document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl1"),
    > document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl3"));
    > which it then references as part of the client side validation.
    > For some reason however, this works perfectly in IE, works fine in my
    > test harness but doesn't work in the release project.


    What excactly happens, what error exactly do you get in the JavaScript
    console for which line?



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Sep 25, 2006
    #2
    1. Advertising

  3. RVB Guest

    It's odd, what -should- happen is that the javacsript fires off on the
    defocus (don't know the exact name) event on the textbox to fire off
    validation at which point, it notes that the test text I've put in is a
    blank space (which works in my test harness on FF).
    What happens is....NOTHING! I fire up the javascript console in FF,
    clear any style complaints it has and try again. No events fired, no
    error messages occur in the console. I am at a complete loss as to
    what's going on.
    I even rechecked agsint the test harness to see the auto generated js
    that gets put in and teh js files that get pulled from webresource.axd
    (the script handler in webcontrols) and, bar the IDs of the field,
    there's no difference.

    Martin Honnen wrote:

    > wrote:
    >
    >
    > > The validator is added to the page validator collection so at run time,
    > > .NET auto generates an array e.g.:
    > > var Page_Validators = new
    > > Array(document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl1"),
    > > document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl3"));
    > > which it then references as part of the client side validation.
    > > For some reason however, this works perfectly in IE, works fine in my
    > > test harness but doesn't work in the release project.

    >
    > What excactly happens, what error exactly do you get in the JavaScript
    > console for which line?
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    RVB, Sep 25, 2006
    #3
  4. ASM Guest

    a écrit :
    > Ok, interesting problem here, I have a webcontrol that holds a textbox
    > and a requiredfieldvalidator from System.Web.UI.Webcontrols in .NET 2.0
    > (this is javascript related, bear with me).
    > The validator is added to the page validator collection so at run time,
    > .NET auto generates an array e.g.:
    > var Page_Validators = new
    > Array(document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl1"),
    > document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl3"));
    > which it then references as part of the client side validation.
    > For some reason however, this works perfectly in IE, works fine in my
    > test harness but doesn't work in the release project. The ONLY possible
    > reason that I can see is that the release project has underscores in
    > the ID and my test harness does not.


    what could break a poor undescore ?

    > Has anyone come across this before?


    never seen an array of functions calling elements ...
    did elements exist before statement of the array ?

    > Please note 2 things:
    > 1) The id attribute is auto-generated by .NET and thus I have extremely
    > limited control over altering it.
    > 2) The array Page_Validators is auto-generated as well and I have
    > absolutely NO entry point with which to alter it so I CANNOT change the
    > method of .getElementById, etc.


    if you can't change anything ... what is the question ?

    I understand you can't do :

    var Page_Validators = new Array(
    "ctl0_ContentPlaceHolder1_UcControl1__ctl1",
    "ctl0_ContentPlaceHolder1_UcControl1__ctl3"
    );

    and only after work with
    document.getElementById(Page_Validators).innerHTML = ... ;

    perhaps could you try

    document.getElementById(Page_Validators.id).innerHTML = ... ;

    --
    ASM
     
    ASM, Sep 26, 2006
    #4
  5. ASM Guest

    RVB a écrit :

    are you : jason.hau ?
    why do you change your identity from post to post ?

    > It's odd, what -should- happen is that the javacsript fires off on the
    > defocus (don't know the exact name) event on the textbox


    which textbox this time ?
    (what is a textbox?)

    eval(Page_Validators.innerHTML = ...);

    ? ?
     
    ASM, Sep 26, 2006
    #5
  6. RVB Guest

    Yeah, I keep forgetting to change to a nickname on groups and only
    remember after my first post >_< (it helps keep down on the spam).

    The textbox itself is just an input tag with type text set against it.
    ASM wrote:

    > RVB a écrit :
    >
    > are you : jason.hau ?
    > why do you change your identity from post to post ?
    >
    > > It's odd, what -should- happen is that the javacsript fires off on the
    > > defocus (don't know the exact name) event on the textbox

    >
    > which textbox this time ?
    > (what is a textbox?)
    >
    > eval(Page_Validators.innerHTML = ...);
    >
    > ? ?
    >
    > .
     
    RVB, Sep 26, 2006
    #6
  7. RVB Guest

    Well, I've just downloaded firebug for firefox which gives me a nicer
    js console and doing document.getElementById worked fine! Very odd.
    Seems to indicate that the validation functions aren't firing. I'll see
    where exactly it's meant to be going.

    Ed Jay wrote:

    > ASM scribed:
    >
    > > a écrit :
    > >> Ok, interesting problem here, I have a webcontrol that holds a textbox
    > >> and a requiredfieldvalidator from System.Web.UI.Webcontrols in .NET 2.0
    > >> (this is javascript related, bear with me).
    > >> The validator is added to the page validator collection so at run time,
    > >> .NET auto generates an array e.g.:
    > >> var Page_Validators = new
    > >> Array(document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl1"),
    > >> document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl3"));
    > >> which it then references as part of the client side validation.
    > >> For some reason however, this works perfectly in IE, works fine in my
    > >> test harness but doesn't work in the release project. The ONLY possible
    > >> reason that I can see is that the release project has underscores in
    > >> the ID and my test harness does not.

    > >
    > >what could break a poor undescore ?
    > >
    > >> Has anyone come across this before?

    > >

    > I don't understand why, but I recently encountered similar behavior with FF.
    > I had to precede all references to document with window, i.e.,
    > window.document.
    > --
    > Ed Jay (remove 'M' to respond by email)
     
    RVB, Sep 26, 2006
    #7
  8. RVB Guest

    Not sure what you mean by "what could break a poor undescore ?".
    While I can't change the output javascript, I can add javascript of my
    own however, I'm not sure what I could add to alter the array/fix this
    problem.
    (The reason I've posted here ,as well as the .NET newsgroups, is that
    its not completely a .NET problem, it's the js that's being produced by
    ..NET that's causing the problem. )

    ASM wrote:

    > a écrit :
    > > Ok, interesting problem here, I have a webcontrol that holds a textbox
    > > and a requiredfieldvalidator from System.Web.UI.Webcontrols in .NET 2.0
    > > (this is javascript related, bear with me).
    > > The validator is added to the page validator collection so at run time,
    > > .NET auto generates an array e.g.:
    > > var Page_Validators = new
    > > Array(document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl1"),
    > > document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl3"));
    > > which it then references as part of the client side validation.
    > > For some reason however, this works perfectly in IE, works fine in my
    > > test harness but doesn't work in the release project. The ONLY possible
    > > reason that I can see is that the release project has underscores in
    > > the ID and my test harness does not.

    >
    > what could break a poor undescore ?
    >
    > > Has anyone come across this before?

    >
    > never seen an array of functions calling elements ...
    > did elements exist before statement of the array ?
    >
    > > Please note 2 things:
    > > 1) The id attribute is auto-generated by .NET and thus I have extremely
    > > limited control over altering it.
    > > 2) The array Page_Validators is auto-generated as well and I have
    > > absolutely NO entry point with which to alter it so I CANNOT change the
    > > method of .getElementById, etc.

    >
    > if you can't change anything ... what is the question ?
    >
    > I understand you can't do :
    >
    > var Page_Validators = new Array(
    > "ctl0_ContentPlaceHolder1_UcControl1__ctl1",
    > "ctl0_ContentPlaceHolder1_UcControl1__ctl3"
    > );
    >
    > and only after work with
    > document.getElementById(Page_Validators).innerHTML = ... ;
    >
    > perhaps could you try
    >
    > document.getElementById(Page_Validators.id).innerHTML = ... ;
    >
    > --
    > ASM
     
    RVB, Sep 26, 2006
    #8
  9. RVB Guest

    Additionally, it shows that the contents of the array are correct in
    that they pick up the spans that contain the error messages.
    (ordinarily works by setting these to visible if there's a problem and
    prevents postback/submit of the page)

    RVB wrote:

    > Well, I've just downloaded firebug for firefox which gives me a nicer
    > js console and doing document.getElementById worked fine! Very odd.
    > Seems to indicate that the validation functions aren't firing. I'll see
    > where exactly it's meant to be going.
    >
    > Ed Jay wrote:
    >
    > > ASM scribed:
    > >
    > > > a écrit :
    > > >> Ok, interesting problem here, I have a webcontrol that holds a textbox
    > > >> and a requiredfieldvalidator from System.Web.UI.Webcontrols in .NET 2.0
    > > >> (this is javascript related, bear with me).
    > > >> The validator is added to the page validator collection so at run time,
    > > >> .NET auto generates an array e.g.:
    > > >> var Page_Validators = new
    > > >> Array(document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl1"),
    > > >> document.getElementById("ctl0_ContentPlaceHolder1_UcControl1__ctl3"));
    > > >> which it then references as part of the client side validation.
    > > >> For some reason however, this works perfectly in IE, works fine in my
    > > >> test harness but doesn't work in the release project. The ONLY possible
    > > >> reason that I can see is that the release project has underscores in
    > > >> the ID and my test harness does not.
    > > >
    > > >what could break a poor undescore ?
    > > >
    > > >> Has anyone come across this before?
    > > >

    > > I don't understand why, but I recently encountered similar behavior with FF.
    > > I had to precede all references to document with window, i.e.,
    > > window.document.
    > > --
    > > Ed Jay (remove 'M' to respond by email)
     
    RVB, Sep 26, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TR
    Replies:
    5
    Views:
    131
    Richard Cornford
    May 19, 2004
  2. Hartmut J?ger

    Firefox and getElementById

    Hartmut J?ger, Nov 27, 2004, in forum: Javascript
    Replies:
    6
    Views:
    150
    Michael Winter
    Nov 28, 2004
  3. Andrea
    Replies:
    5
    Views:
    201
    Thomas 'PointedEars' Lahn
    Nov 30, 2005
  4. the other john

    getElementById and Firefox

    the other john, May 24, 2006, in forum: Javascript
    Replies:
    4
    Views:
    142
    the other john
    May 24, 2006
  5. the other john

    getElementById and Firefox

    the other john, May 24, 2006, in forum: Javascript
    Replies:
    0
    Views:
    164
    the other john
    May 24, 2006
Loading...

Share This Page