Forums / Bug Reports / [Done v1.3.6] javascript not validating

[Done v1.3.6] javascript not validating

Locked
Results 1 to 3 of 3
This thread is locked. New replies are disabled.
23 Oct 2006, 07:14
#1
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Posts:
1,033
Plugin Contributions:
3

[Done v1.3.6] javascript not validating

Its a simple problem... but there's a javascript snippet being used by several pages that looks like this:
<script language="javascript"><!--
function resetZoneSelected(theForm) {
  if (theForm.state.value != '') {
    theForm.zone_id.selectedIndex = '0';
    if (theForm.zone_id.options.length > 0) {
      theForm.state.value = '<?php echo JS_STATE_SELECT; ?>';
    }
  }
}

function update_zone(theForm) {
  var NumState = theForm.zone_id.options.length;
  var SelectedCountry = "";

  while(NumState > 0) {
    NumState--;
    theForm.zone_id.options[NumState] = null;
  }

  SelectedCountry = theForm.zone_country_id.options[theForm.zone_country_id.selectedIndex].value;

<?php echo zen_js_zone_list('SelectedCountry', 'theForm', 'zone_id'); ?>

}
//--></script>


Technically, this does not validate. To see what I mean, just go to validator.w3.org and paste in the source from a login page. Its also on address book, checkout payment, checkout shipping, and create account.

- Steven
23 Oct 2006, 08:06
#2
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Posts:
1,033
Plugin Contributions:
3

Re: [Done v1.3.6] javascript not validating

Doing a bit of reading on the W3C validation FAQs... it seems that XHTML and the common practice of "hiding" scripts (for backward browser compatibility) by using <!-- and //-->, are at odds. It simply recommends you NOT do it. However, if you take them out, you get a whole lot of other validation problems if your scripts include any of the following charactersets

&
]]
--
<

which so many of them do.

Solution?

They recommend using ONLY externally linked js.

Honestly I don't know how important it is to have "valid" code... but perhaps that's a direction to take for an upcoming release?

- Steven
27 Oct 2006, 21:09
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,506
Plugin Contributions:
173

Re: [Done v1.3.6] javascript not validating

Two aspects of this were addressed in the 1.3.6 release:
1. the "type" attribute was added to the SCRIPT tag
2. the NumState--; was changed to NumState = NumState - 1;

It may also have worked to use -= 1 instead of restating the var name etc.