Non-deprecated equivalent of <form target="..."> - html

I want to achieve the same as...
window.open('lalala.php', 'lalala', '...');
But I want to send a HTTP POST request instead of a HTTP GET request. Thus, I'm using the following:
$('<form/>').attr('action', 'lalala.php')
.attr('target', 'lalala') // w3schools.org says this is deprecated
.attr('method', 'post')
.append(hiddenParam('param1', param1))
.append(hiddenParam('param2', param2))
.submit().remove();
// hiddenParam is a function I created that returns an input tag
// the type attribute set to hidden,
// the id attribute set to the first parameter,
// and the value attribute set to the second parameter
However, the target attribute is deprecated. Is there any way to achieve what I'm trying to do by non-deprecated means?

Use target — it isn't deprecated.

target is only missing in strict doctypes. It is not deprecated. The simplest solution is to use a transitional doctype.
All browsers that I am aware of do the right thing, even if you use a strict doctype.
If you must use a strict doctype, and you care that much about validation, then you can extend the doctype definition:
Just be aware of this 'bug' in just about every browser. The solution is to serve your XHTML as application/xhtml+xml, but this will cause IE to blow up, so you need to sniff for that browser before determining the content type. It's essentially one giant hack for a tiny check box on a validation form. It's usually a lot simpler to just use a transitional doctype.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [ <!ATTLIST form target CDATA #IMPLIED> ]>

Add
<form target="lalala" ...></form>

Related

HTML Validation

My website is almost ready but I notice that my website shows in Firefox and IE look different and in chrome is fine. I have used HTML Validation to check and have 2 errors and 2 warnings. This is the details :
Line 2, Column 13: there is no attribute "XMLNS"
<html xmlns="http://www.w3.org/1999/xhtml">
✉
You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).
This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.
How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute. If you received this error when using the element to incorporate flash media in a Web page, see the FAQ item on valid flash.
Line 4, Column 76: NET-enabling start-tag requires SHORTTAG YES
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
✉
For the current document, the validator interprets strings like according to legacy rules that break the expectations of most authors and thus cause confusing warnings and error messages from the validator. This interpretation is triggered by HTML 4 documents or other SGML-based HTML documents. To avoid the messages, simply remove the "/" character in such contexts. NB: If you expect to be interpreted as an XML-compatible "self-closing" tag, then you need to use XHTML or HTML5.
This warning and related errors may also be caused by an unquoted attribute value containing one or more "/". Example: http://w3c.org>W3C. In such cases, the solution is to put quotation marks around the value.
Line 4, Column 77: character data is not allowed here
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
✉
You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include:
putting text directly in the body of the document without wrapping it in a container element (such as a aragraph), or forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or using XHTML-style self-closing tags (such as ) in HTML 4.01 or earlier. To fix, remove the extra slash ('/') character. For more information about the reasons for this, see Empty elements in SGML, HTML, XML, and XHTML.
Line 44, Column 12: NET-enabling start-tag requires SHORTTAG YES
<br/>
✉
For the current document, the validator interprets strings like according to legacy rules that break the expectations of most authors and thus cause confusing warnings and error messages from the validator. This interpretation is triggered by HTML 4 documents or other SGML-based HTML documents. To avoid the messages, simply remove the "/" character in such contexts. NB: If you expect to be interpreted as an XML-compatible "self-closing" tag, then you need to use XHTML or HTML5.
This warning and related errors may also be caused by an unquoted attribute value containing one or more "/". Example: http://w3c.org>W3C. In such cases, the solution is to put quotation marks around the value.
As for Line 2, Column 13, I have added in this under header.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
However, this error is still there and I really do not know how to tidy it. On top of that, I am not a programmer and very poor in HTML....
Thank you.
You are trying to validate a document with some XHTML features as HTML 4. You are not showing the first line of the HTML document, and this would be all-important. In general, you should show a complete HTML document that reproduces the issue. But in this case, the apparent reason is wrong DOCTYPE. You should replace the existing HTML 4 DOCTYPE by one that declares some version of XHTML 1.0, if XHTML 1.0 is what you are trying to use.

One W3C validation errors I really want to correct

This would be my first website and I do not want to leave it these errors. Can someone please help me with these ones?
Error 1:
if (xmlhttp.readyState==4 && xmlhttp.status==200)
error: character "&" is the first character of a delimiter but occurred as data.
WHEN i &, then my AJAX code stops working
I have no clue how to correct this one.
Error 2:
…ems"><a href="brushdescription.php?id=<?php echo $popularbrushesrow['bd_brushi…
error: character "<" is the first character of a delimiter but occurred as data
Again the same error but for < this time
UPDATE:
I am using this doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< and & are some of the predefined entities in XML, which need escaping when validating the page as XML or XHTML.
< should be replaced with < (less than)
& should be replaced with & (ampersand)
However, if using these characters in JavaScript you can (instead) enclose the script in a <![CDATA[]]> section, which instructs the parser to not interpret the code as markup and will also not result in a validation error.
Try wrapping your Javascript with <![CDATA[]]> tags like so:
<script>
//<![CDATA[
// Javascript goes here.
//]]>
</script>
Also, you should look into separation of concerns. Try to move your logic out of you view. If your Javascript is in your HTML page, try to include it from a separate file.
From Wikipedia:
HyperText Markup Language (HTML), Cascading Style Sheets (CSS), and JavaScript (JS) are complementary languages used in the development of webpages and websites. HTML is mainly used for organization of webpage content, CSS is used for definition of content presentation style, and JS defines how the content interacts and behaves with the user. Historically, this was not the case though. Prior to the introduction of CSS, HTML performed both duties of defining semantics and style.
Use HTML, not XHTML (or, if you insist on using XHTML, see the guidelines on how to write XHTML that can be parsed as HTML).
I can't see how you could have generated that error. Some more context would be useful.
For the first error, consider switching from XHTML to HTML5. There's really little reason to use XHTML. Use this:
<!DOCTYPE html>
The W3C validator is for client-side code, but it seems you are trying to validate server-side code, hence the PHP tag. Send the rendered code for validation and the second error will go away. The rendered code is the one visible in the browser under "View source". You can supply the URL if it's already online somewhere.
By XML rules, “The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " & " and " < " respectively.” So “&&” is to be written as &&.
However, this is such works only when the document is processed as “real XHTML” due to having been sent with an XML content type, e.g. with the HTTP header Content-Type: application/xhtml+xml. Doing so implies that old versions of IE will choke on it and modern browsers will refuse to render the document at all if it contains any well-formedness error. People don’t normally do that – they just use XHTML because someone told them to do so, and their documents are sent with an HTML document type, which means among other things that script element content is processed differently. This explains why a fix that satisfies the validator makes the page break.
In the XHTML 1.0 specification, the (in)famous appendix C says: “Use external scripts if your script uses < or & or ]]> or --.” This is the simple cure if you need to use XHTML. Just put your script in an external file and “call” it with <script src="foo.js"></script>.

Get rid of “Bad value X-XRDS-Location for attribute http-equiv on XHTML element meta.” in XHTML5 validation

I have an XHTML 5 page served with application/xhtml+xml which I want to get to validate, but the validator gives me trouble in its validation results:
Line 17, Column 89: Bad value X-XRDS-Location for attribute http-equiv on XHTML element
The line in question is:
<meta http-equiv="X-XRDS-Location" content="http://shlomif.livejournal.com/data/yadis" />
How can I fix this problem? Was an arbitrary "http-equiv" value removed from the XHTML 5 specification?
http://www.w3.org/TR/html-markup/meta.html says:
Changes in HTML5
Although previous versions of HTML allowed the http-equiv attribute on the meta element to have any number of possible values, the http-equiv attribute is now restricted to only the specific values described in this reference. Also, the new charset attribute is now allowed.
So, yes, it is not allowed anymore.
In (X)HTML5, you may only use http-equiv values that are
defined in the HTML5 spec, or
registered in the WHATWG wiki page "PragmaExtensions".
If you think X-XRDS-Location would be a useful value, you’d have to register it.

How to replace with   in an html file

I want to replace all the with   in my html file to support XML parser.
But I don't want to replace them directly, I'd like to add an entity in <!DOCTYPE > like below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[<!ENTITY nbsp " ">]>
<html><head></head><body><div>Hello World!</div></body></html>
But when I view the file, there is an extra ]> on the top of the document:
Anyone know how to deal with it?
Thanks!
What you have is a valid way to include an entity declaration in an internal subset. The document is not otherwise valid, though, as you can check with the W3C Markup Validator: the required xmlns attribute on the html element is missing, and so is the required title attribute.
When served as text/html, the document is processed how browsers use to process HTML document, which means among other thing that internal subsets are not recognized; in fact, document type definitions are not read at all – instead, doctype declarations are just taken as magic strings so that some strings trigger “quirks mode”, some don’t. The doctype declaration is parsed in a simplistic manner, which makes the first “>” terminate it, so whatever comes after it is taken as character data.
The morale is that entity declarations just don’t work with “HTML”, internally or externally, when “HTML” means sending something to a browser and telling (in HTTP headers) it to be text/html – and that’s what servers normally tell when they send .html files.
Served as application/xhtml+xml and fixed to conform to XHTML syntax, your approach works on conforming browsers (online demo: http://www.cs.tut.fi/~jkorpela/test/nbsp.xhtml):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[<!ENTITY nbsp " ">]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Entity demo</title></head>
<body>
<div>Hello World!</div>
</body>
</html>
However, IE 8 and earlier don’t process HTML when served as application/xhtml+xml (the browser just launches a “Save As” dialog).
The conclusions depend on what you are doing and why (and in which sense) you need to “support XML parser”. It’s not really about parsing but about entity declarations. XHTML user agents are not required to understand predefined entities as in HTML (except for those defined in XML), but has this possibility realized somehow? And in general, it is better to convert to actual no-break space characters than to character references.
here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[<!ENTITY nbsp " ">

autocomplete attribute is not passing XHTML 1.0 Transitional validation, why?

I'm trying to cleanup my xhtml validation -- I'm running my pages through the W3C validator. For some puzzling reason it's not passing on input fields with the autocomplete="off" attribute:
<input name="kwsearch" id="sli_search_1" type="text" autocomplete="off" onfocus="if(this.defaultValue==this.value) this.value='';"
onblur="if(this.value=='')this.value=this.defaultValue;" class="searchbox" value="Search" />
I'm using this doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
And this is the validation error:
Line 410, Column 81: there is no attribute "autocomplete"
…li_search_1" type="text" autocomplete="off" onfocus="if(this.defaultValue==thi…
I thought this was okay with the W3C -- but, maybe it's still in "submission" phase?
http://www.w3.org/Submission/web-forms2/#autocomplete
Thoughts?
The Web forms specification has nothing to do with HTML 4 / XHTML. Sadly, autocomplete will not pass validation.
I think the only way to achieve valid HTML 4 /XHTML with autocomplete turned off is adding the attribute on page load using JavaScript. Sucks, I know - but I think it's the only way.
autocomplete is a HTML5 attribute, so use a HTML5 document type declaration, if you need it.
That W3C link is for the web forms stuff, not core XHTML. It might be possible to pull in the extra DTD for the web forms and get the page to validate.
If you need autocomplete( browsers do support it ), then try extending your doctype, like in this XHTML 1.1 below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" [
<!ATTLIST form autocomplete (on|off) #IMPLIED>
]>
I've just banged up against this irritating conflict between browsers and standards. I ended up getting around it by running javascript ON THE PAGE, not waiting for window.onLoad or $(document).ready(), to add the attribute to all elements with the class no-browser-autocomplete. Then i went through my app removing autocomplete="off" and adding this class instead.
Obviously this will fail in browser environments not running javascript.
The reason that i do it on the page, rather than in a dom ready block, is that if you wait for dom ready, the browser's already autocompleted it, at least in Firefox (which i'm testing it in).
So, this is at the start of one of the javascript files i include in my app layout:
//this needs to run BEFORE all of the loaded/ready events fire, that's why it's not in the dom.ready function
$(".no-browser-autocomplete").attr("autocomplete", "off");
$(function(){
//dom ready
});