Jump to content

Form submits in HTML output of XSLT transformation do not get honored


Recommended Posts

Dear forum,My site uses XML pages. They are presented to the clients via XSLT.The server runs IIS 7.5. With the help of this forum and some Web research I added an ASP handler to be able to process ASP scripts.[see 1]Scripts can be processed now, and all works fine as it should, with one exception:I have encoded an XML form, which is presented to the client (via XSLT) as a HTML form.[see 2] Submitting this form (via submit button or javascript-executed button) does work only in IE 8 and IE 9, but not in Firefox, Chrome or Opera: the latter 3 all ignore the call.This is somewhat perplexing, because copying the whole presented HTML output into a test file with a html extension (as opposed to the original xml extension) and calling this html file shows absolutely no problems in Firefox etc.I understand that the problem is quite complex, given that it involves XML/XSLT, ASP scripting and Javascript. However, any pointer towards a solution, or at least towards problem isolation, would be highly appreciated.Thanks in advance,Donar[1] http://w3schools.invisionzone.com/index.php?showtopic=36758[2] http://www.gandraxa.com/solving_linear_rec...e_sequences.xml

Edited by Donar
Link to post
Share on other sites

If Javascript is submitting the form, then the first thing to do is check the Javascript consoles in the other browsers for error messages. Each of them has a way to check for errors, and if there's an error in the code you'll see it there.

Link to post
Share on other sites

Yes, thank you for your remarks. However, the form isn't being submitted at all (except in IE 8 and 9) - it reacts to a click as if the referenced function was not defined at all. But since the output generated by XSLT is presented to the client as pure HTML/Javascript (which can be verified in above ref [2]), one should assume that the function is there. Could it be that 3 known browsers are doing that wrong? I tend to search the error on my side. (Funny thing is, of course, that for once it works with cursed IE and not with the others.)Also, as I wrote: When I copy the output generated by XSLT (pure HTML/Javascript) to a new file, then all browsers work just fine.Regards,Donar

Edited by Donar
Link to post
Share on other sites
Also, as I wrote: When I copy the output generated by XSLT (which is presented to the user as pure HTML/Javascript, which you can verify in above ref [2]) to a new file, all browsers work just fine, so it is not a JS issue per se...
Then why do I see a Javascript error when I click submit?Like I said, error consoles should always be step 1 in debugging problems like this. Don't assume anything, verify it.
Link to post
Share on other sites

Yes, thank you. It just says that said function is not defined, and so it reacts.Are you using Mozilla Firefox? May I ask you to use Ctrl-A on the page and view the source code, please? It is very well possible that there is an error in my script (however, in that case the IE would not complain). (Viewing the source without marking anything will just show the raw XML).Now, the pure existence of that error tells, that we are "beyond XML", so to say, because XML would have no clue what <form> means and react at it like it would with <notunderstood>. So we are in the "HTML/JS view", in which a <form> has a defined meaning. Only that it won't do what it should.Well, that is *my* understanding of the things. Somewhere I am wrong, I feel this, but I still do not see it.In the meantime, thanks for your time, it's appreciated.

Link to post
Share on other sites

Opera and Firefox show different results, and that's because each browser is doing its own XML transformation. If you're going to use XML, you're adding another point of failure because you're relying on each individual browser to essentially generate its own markup instead of giving them all the same thing which you know works. Opera, for example, shows an exception inside the Javascript function on the last line, while Firefox doesn't even see the function in the first place. The code that each browser generates is slightly different with the comments:Opera:

<script language="JavaScript">				function doSubmitForm(formid)			{					var url = document.URL;				var querypos = url.indexOf("?");				if(querypos!=-1)				{	url = url.substr(0,querypos); }								var children = document.forms(formid).childNodes;				var namevalue = "";				for(i=0;i<children.length;i++)				{	if(children[i].tagName=="INPUT")					{	if(children[i].type=="text")						{	if(children[i].value.length!=0)							{	if (namevalue.length == 0) 								{	namevalue = "?" }								else								{	namevalue += ";" }									namevalue += children[i].id + "=" + children[i].value;							}						}					}				}				url += namevalue;				document.URL = url;			}		// --></script>

Firefox:

<script language="JavaScript"><!--			function doSubmitForm(formid)			{					var url = document.URL;				var querypos = url.indexOf("?");				if(querypos!=-1)				{	url = url.substr(0,querypos); }								var children = document.forms(formid).childNodes;				var namevalue = "";				for(i=0;i<children.length;i++)				{	if(children[i].tagName=="INPUT")					{	if(children[i].type=="text")						{	if(children[i].value.length!=0)							{	if (namevalue.length == 0) 								{	namevalue = "?" }								else								{	namevalue += ";" }									namevalue += children[i].id + "=" + children[i].value;							}						}					}				}				url += namevalue;				document.URL = url;			}		// --></script>

I would remove the comments altogether. If the browser can process an XML tranformation, it's not going to blow up when it sees Javascript. Firefox also adds an extra meta tag, it has 2 content-type tags that are set differently. One is UTF-8, and one is ISO-8859-1. Opera only shows the ISO encoding. I'm not sure which encoding Firefox is actually using since there are 2 tags. If I run the two complete sets of code through a compare tool I can see several other small differences between the two. One change you should make is that the script tag should use the type attribute instead of language.I've heard this saying using various languages, but XML is pretty common: some people, when faced with a problem, think "I know, I'll use XML!" Now they have 2 problems.

Link to post
Share on other sites

I changed the original

<script language="JavaScript"><xsl:comment>	// code// </xsl:comment></script>

to

<script type="text/javascript">	// code</script>

IE still processes the submit request, FF still does not process it.But the FF error console changed now to:"Error: document.forms is not a function"That's it, something changed, and you guided me to the right track right from the beginning, as I now acknowledge.Of couse, in this line:

var children = document.forms(formid).childNodes;

JS wants [...], not (...), even if recognized by IE.IE still works, FF not, but now it says:"Error: setting a property that has only a getter"The only possible line in question was:

document.URL = url;

Now even if supported by the IE, the official statement must be

location.href = url;

of course.And ya baby, it works in all browsers ("all" = IE, FF, Chrome, Opera). How can I thank you?Regards,Donar

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...