Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a form action to open in new window 3

Status
Not open for further replies.

Graeme06

Technical User
Jun 6, 2006
60
Hi I currently have some HTML code which I pasted below (there is more to it, but those are the relevent parts).

I want to get valid strict XHTML, and it does not like the target="_blank", so someone suggested using Javascript and an onclick. The problem being that the action happens in the form tag, not the input button's tag, so I don't know how I can fix this. I tried putting the javascript code in both the form and input button tags, but neither worked properly. Any ideas?

Thanks,
Graeme


------------------
<form action="search.php" method="post" target="_blank" id="search" title="search" dir="ltr" lang="en">

<input name="submit" type="submit" id="submit" class="google" tabindex="3" value="Search" />


</form>
 
you cannot validate stict XHTML and use target in the form tag.

you may dynamically be able to add the target attribute to the form tag via javascript via the onclick event or simply ignore the error when validating if it's the only one.

or use Transitional doctype that allows target in the from tag

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
how about
Code:
<form action="search.php" method="post" [b]onsubmit="this.target='_blank';"[/b] id="search" title="search" dir="ltr" lang="en">

-jeff
lost: one sig, last seen here.
 
that'll work ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I want to get valid strict XHTML, and it does not like the target="_blank"

Curious. Reading the W3 schools tutorial on XHTML I find exactly that attribute listed.
What is the "it" that does not like this attribute? And what is the message "it" gives?

If it were me, and admittedly I dont code to XHTML standards, I would write target="new", or something descriptive, target="displayForm". Would that not be strictly valid XHTML?
 
Yes, I see that on second look. Thank you.

I know this has all been discussed and agreed upon at the highest levels by experienced folk who set the standards, but when I read
Use this when you want clean markup, free of presentational clutter. Use this together with Cascading Style Sheets (CSS):

Then I see that dir="ltr" is valid in Strict, I have to say it seems arbitrary to make target not Strict.

Really, I always sort of thought of HTML as being all about presentation.
 
thank you jemminger, works excellent.
 
Really, I always sort of thought of HTML as being all about presentation.

To be semantic, CSS is about 'presentation', X/HTML is about 'content'.

The reason the 'target' attribute not being allowed is due to the strong belief in 'web standards' that the 'back' button should never be broken and all links should load the target page in the current window.

Whether you agree with this or not, that's what the 'powers @ be' have decided!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I suppose that kind of makes sense. New windows are pretty annoying (especially now with tabbed browsing). The only reason I'm using it is because that part of the code that I was validating was written by someone else, and I wanted to validate it without changing the functionality.
 
yup - i'm forever hitting a brick wall when it comes to 'functionality' vs 'the standards' - lol

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
It is not so much that I disagree with the standard. But sometimes it is instructive to examine the way things are and how they came to be. Take the term "markup language". See .

Interesting about the Back button always working. Really then what we have accomplished with the Javascript approach is to circumvent that desirable feature and still produce a Strict XHTML document.

Simplicity in code is important too. I am afraid with this matter of the target attribute the XHTML standard is second-best.

Non-compliant and simple. Just works.
Code:
<form action="search.php" method="post"  target="_blank" id="search" title="search" dir="ltr" lang="en">

Compliant and complex. Fails if Javascript is not enabled.
Code:
<form action="search.php" method="post" onsubmit="this.target='_blank';" id="search" title="search" dir="ltr" lang="en">
 
well i'm very bad at harnessing JS and most of my websites would break with JS turned off, personally I have no idea why anyone would be surfing the web with a non-JS capable browser or with it switched off.

That's like having a top of the range car then turning the ABS, Air Bags, Power Steering and Fuel Injection off, makes no sense to me!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top