Document type does not allow element "span" here? - validation

I am working on getting my XHTML validated.
In my page, I have dynamic creation (in JS) of many HTML elements.
For example, I have a for loop that parses an Array that hold value's of a select tag, and then my JS code created the select with the given values. Therefore, my JS contains HTML elements inside quotes (strings). Unfortunately, I cannot get my XHTML validated because the validator things that these guys are actual elements.
How do I avoid this? Is is necessary to avoid this?

You'll need to tell the XHTML validator to parse your JavaScript different then the rest of your code. You can do this by using CDATA blocks in your script tags.
Example:
<script type="text/javascript">
//<![CDATA[
...code...
//]]>
</script>
For more information for as to why, see the question When is a CDATA section necessary within a script tag?

Related

How to extract javascript text with xpath

Is it possible to extra a part of a javascript which is not visible with use of xpath?
<script type="text/javascript"> "agri_discount_group":"","agri_discount_text":"Promoties ","reindex":"1","list_name":"","list_active_variant":"0","list_is_single":"","recalc_rules":"0","agri_discount_type9_art":"","dropshipment":"","leadtime_dropshipment":"0","leadtime_delivery_extra_costs":"","agri_discount_start":"1675033560","agri_discount_stop":"1676242740","stock_feed":"2","stock_feed_tstamp":"1675396701","default_scancode":"8710429017146","tstamp_first_online":"1558595899", </script>
I now how i get a whole text of a div/span tag which is visible on the website but not how i can extract the data which is not visible on the frontend (but is on the source code). And secondly i am not sure how i can only select the code behind the text element "default scancode". Is this possible?
I use octoparse to extract the info from a website.
Edit:
This part of the code is what i am looking for:
Code element . The entire page source is shown here:
source code

Scrapy selector outside html tag

I have a special case where a script tag is placed outside the html tag :
<html>
....
</html>
<script>data</script>
both css and xpath selectors are not finding this script tag, the only way I found is using response.text , but that responds with a giant string and I can not make regex operations on it with selector re() function.
Is there a way to CSS or Xpath tags outside html tag?
I tried with
response.css('script')
But only consider script tags inside html tag
Thanks
Correction :
css selector does not consider tags outside HTML , xpath does.
I used some conditions to filter the tag :
response.xpath('//script[contains(., "function SelectItem()")]')

W3C Validation Error: document type does not allow "strong"

I want to append some text in the HTML document using jQuery. The font weight of the appended text should be BOLD. For that I do this:
<script type="text/javascript">
$('.append-here').append('<strong>'+$.cookie('XYZ')+'</strong>'));
</script>
It works like this but this gives me W3C error: document type does not allow element "strong" here.
Now, if I write strong tag outside script tag, it doesn't work.

Handlebars template with "div" tag instead "script"

Actually the question is in the subj...
Is it possible to make handlebars template framework, to recognize templates within a div tag and not in script tag?
For example I would like to create template with this markup:
<style>
div.text-x-handlebars {display:none;}
</style>
<div class="text-x-handlebars-template">
<h2>I'm template</h2>
<p>{{welcomeMessage}}</p>
</div>
Yes you can put your templates in <div>s rather than <script>s, for example:
http://jsfiddle.net/ambiguous/RucqP/
However, doing so is fraught with danger. If you put your template inside a <div> then the browser will interpret it as HTML before you've filled it in; so, if your template's HTML isn't valid until after it has been filled in, the browser may attempt to correct it and make a mess of things. Also, if you have id attributes in your templates, then you will end up with duplicate ids (one in the template <div> and a repeat in the filled in template that you put in the DOM) and that will cause all sorts of strange and interesting bugs. The browser will also try to download any images inside the templates in a <div>, this may or may not be a problem (if might even be desirable but probably not desirable if the image uses a template variable in its src attribute).
Basically, you can do it but you shouldn't, you should put your templates in <script id="..." type="text/x-handlebars-template"> elements instead.

Why does form validation not work in MVC3 partial views?

Anybody? There is another question regarding this but the only answers were to code up some javascript validation, which also refuses to work on my partial view ("$ is not defined").
Anyway, I don't want to use javascript I just want simple validation for required fields that cannot be left blank, number fields that require ints, etc.
Can anyone shed some light on validation and partial views?
I suspect that you are loading those partial views using AJAX. If this is the case you will need to manually invoke the $.validator.unobtrusive.parse method once you inject the new contents of the partial into the DOM as explained in this article.
Brad Wilson also discussed this in his blog post:
The unobtrusive client validation script automatically parses the
initial set of HTML for validation rules when the page has finished
loading. If your page dynamically adds new HTML content (perhaps
throught Ajax or through client-side application code), you may wish
to parse that new HTML for client validation on the new HTML elements.
To parse new HTML, you can call the
jQuery.validator.unobtrusive.parse() method, passing it a selector for
the HTML that you would like to be parsed. You can also call the
jQuery.validator.unobtrusive.parseElement() function to parse a single
HTML element.
As far as the $ is not defined error you should make sure that you have included the proper scripts:
<script src="#Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Also make sure you are not referencing any of the Microsoft*.js scripts. They are obsolete and should no longer be used in ASP.NET MVC 3.
Of course that's only a supposition, you haven't shown any code so we cannot know what you are doing.
I'm having the same problem and i found that it's not possible to call $.validator.unobtrusive.parse() on the same form twice.
When loading the form initially from the server the form is parsed automatically by the unobtrusive library. When you add an input element dynamically to the form and call $.validator.unobtrusive.parse() again, it won't work. The same goes for parseElement().
So before you call $.validator.unobtrusive.parse, remove the original validator and unobtrusive validation from the form like so:
success: function (html) {
$("#div-id").append(html);
var form = $("#div-id").closest("form");
form.removeData('validator');
form.removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse($("#editorRows"));
}

Resources