Range Validator giving javascript error

Last post 05-20-2008 5:00 PM by GotAByte. 2 replies.

Sort Posts:

  • Range Validator giving javascript error

    05-14-2008, 3:43 PM
    • Loading...
    • GotAByte
    • Joined on 06-21-2006, 8:30 PM
    • Minneapolis,MN
    • Posts 16

    I am having an issue with a RangeValidator control giving an javascript error.  This does not occur all the time, but I am guessing only when a control name is formatted in a certain way. 

    Here is an example of a page I am having trouble with.

    http://www.creativememories.com/MainMenu/Our-products-and-services/Traditional-Scrapbooking/Albums---NEW-Sizes!/8x8-Albums---NEW-Sizes/8x8-Coversets/8-x-8-Coverset-Ruby

    Offending line 

     1    var 8_X_8_Coverset_Cobalt_ProductCatalogUserControl_ctl00_ProductCartControl_QuantityI18NRangeValidator = document.all ? document.all["8_X_8_Coverset_Cobalt_ProductCatalogUserControl_ctl00_ProductCartControl_QuantityI18NRangeValidator"] : document.getElementById("8_X_8_Coverset_Cobalt_ProductCatalogUserControl_ctl00_ProductCartControl_QuantityI18NRangeValidator");

    Similar line on another page with no issues.
    2    good var PicFolio™_Max_Album_Blue_12_x_12_ProductCatalogUserControl_ctl00_ProductCartControl_QuantityI18NRangeValidator = document.all ? document.all["PicFolio™_Max_Album_Blue_12_x_12_ProductCatalogUserControl_ctl00_ProductCartControl_QuantityI18NRangeValidator"] : document.getElementById("PicFolio™_Max_Album_Blue_12_x_12_ProductCatalogUserControl_ctl00_ProductCartControl_QuantityI18NRangeValidator");

     

    any help is greatly appreciated

     
    Thanks,
    GotAByte
  • Re: Range Validator giving javascript error

    05-14-2008, 6:47 PM
    Answer
    • Loading...
    • nmgomes
    • Joined on 04-09-2007, 11:53 PM
    • Portugal
    • Posts 216

     Hi,

    In javascript, variables name cannot start with numbers, so var 8x8.... will return an error and var _8x8... will work fine.

    If you are dynamically generating the javascript var name then append the '_' char at the name beginning and all var names will be valid.

    Nuno Gomes [visit my blog]
    Portugal - Europe's West Coast
    [Don't forget to click "Mark as Answer" on the post(s) that helped you.]
  • Re: Range Validator giving javascript error

    05-20-2008, 5:00 PM
    • Loading...
    • GotAByte
    • Joined on 06-21-2006, 8:30 PM
    • Minneapolis,MN
    • Posts 16

    Thanks so much for the note. This was exactaly my problem. 

     To fix this I created a regular expression to remove all inalid javascript errors from my control name.  Also used regex if there is a number at the begining of the control I put in an underscore.

    This saved me a ton of research time.Big Smile

    Thanks,
    GotAByte
Page 1 of 1 (3 items)