Click to See Complete Forum and Search --> : problems getting & testing value from forms


vinitharya
03-21-2005, 09:01 PM
Hi,

I have an html page that asks for some input, does some calculations, and then prints some output. It works nicely as just plain html, but I want to convert it to xhtml in order to be able to show some nice mathml rendering. However, the conversion is causing trouble getting the value of input & testing it. Here's the piece I am having trouble with:


<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"xhtml-math11-f.dtd"
[<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">]>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Argh!!!!!!!!!</title>
<script language="javascript">
function check_delta()
{
var x=document.delta_form.Xdelta.value;
alert("The value of delta is: " + x);
}
</script>
</head>

<body>
<center>
<h1>Why won't this stupid thing work?</h1>
<form name="delta_form" >
Input a value for delta:
<input type="text" name="Xdelta" onchange="check_delta();" />
</form>
</center>
</body>

</html>


The line
var x=document.delta_form.Xdelta.value;
which works well as *.html, no longer works if I save the file with a *.xhtml extension. I never see the alert popping up to confirm the value entered, and the value entered disappears from the input box. If I replace this line with x=3, then the alert popup works.

So how do I access the value that was entered into the form?

A second question concerns how to test the value retrieved. The xml parser complains about lines like:
if (0<=y && y<=1) { /* stuff */ }
saying they are poorly formed. I know it's getting hung up on the angle brackets, because it accepts things like
if (0==y && y==1) { /* stuff that will now never happen */ }

So how do you do comparisons without angle brackets?

I am having these problems in Firefox 1.0.1, Mozilla 1.7.2, and Netscape 7.2,in both Windows XP & Fedora Core 3.

Sorry for such newbie type questions, and apologies if this should go in a different forum!

Cstick
03-21-2005, 09:40 PM
Try these changes.


<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"xhtml-math11-f.dtd"
[<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">]>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Argh!!!!!!!!!</title>
<script language="javascript">
<!--
// Cross browser compatible object reference.
// Use getObject('id') to reference elements.
function getObject(obj){if(document.getElementById){return document.getElementById(obj);}else{if(document.all){return document.all[obj];}}}

function check_delta()
{
//Scratch this and use below.
//var x=document.delta_form.Xdelta.value;
var x = getObject('Xdelta').value;
alert("The value of delta is: " + x);
}
//-->
</script>
</head>

<body>
<center>
<h1>Why won't this stupid thing work?</h1>
<form name="delta_form" id="delta_form" >
Input a value for delta:
<input type="text" id="Xdelta" name="Xdelta" onchange="check_delta();" />
</form>
</center>
</body>

</html>


The above worked fine for me in Firefox. Except for the fact that it rendered the end of this line, I don't think it is formatted correctly. It renders the last 2 characters "]>".


[<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">]>

vinitharya
03-21-2005, 10:22 PM
Wow, that was fast--thanks!

Your code works perfectly if the file is saved with *.html extension. However, if you save it with *.xhtml extension, the same problem that I had still exists--you never get to the alert popup acknowledging the value the user put in, and the value he/she input disappears from the input box.

I need the *.xhtml extension because the mathml expressions in other parts of the page will only render correctly with *.xhtml; they don't render properly with *.html.

In the expression [<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">]>the final closing angle bracket is actually paired to the opening angle bracket from <!DOCTYPE html This is correctly recognized by the browser if the file extension is *.xhtml, and no "]>" appears in the rendered page. If the file extension is *.html, then I also see the "]>" rendered onto the page.

I am totally missing something fundamental about how *.xhtml is different from *.html. Both of the lines
var x=document.delta_form.Xdelta.value; or var x=getObject('Xdelta').value should work, but they don't, and I don't understand why.

Thanks for the reminder to comment out the javascript code with "<!-- ... //-->". That solved the problem of expressions like "if (0<x && x<1)" getting flagged because of the angle brackets.

Cstick
03-22-2005, 07:24 PM
Are you certain that you have to use .xhtml extension? If you are simply trying to create pages that are xhtml compliant then you can name them .htm, .html, .aspx, .php, .whatever! The point is that you have the right DTD and of course, your code is xhtml.

I don't know anything about MathML, but if it requires an extension of .xthml then I guess you have to use it, otherwise, you absolutely do not have to use .xhtml as an extension.

Furthermore, the reason your JS only worked in IE previously and now works in mozilla and IE is because the getObject method is able to get an object's ID regardless of browser. Also, if you say it stopped working when you changed extensions from html to xhtml, then I would have to believe that the code has changed somehow. Because the file's extension will not make a difference with the JS functionality.

Also, html vs. xhtml will not affect JS. It works regardless.

Hope this helps.

vinitharya
03-26-2005, 11:37 PM
Empirically, the mathml does not render properly unless the ending is *.xhtml or *.mml, and none of the mathml sites produced by google have a plain *.html ending.

The contents of the file did not change after renaming the ending. The behavior of javascript per se also appears not to have changed--if one replaces "var x = document.delta_form.Xdelta.value" or "var x = getObject('Xdelta').value" with "x=3", then the popup alert shows up perfectly fine.

So it appears that what's different is not javascript, but the nature of the DOM under html vs xhtml. The "topnode.nextnode.nextnode.value" and "getElementBySomeLabel('label').value" approaches, which both work under html, don't work under xhtml. I've tried searching for info on how to access user-input data under the xhtml DOM, but unfortunately have found nothing practically helpful. :confused:

Thanks for trying to help though!

Cstick
03-27-2005, 06:54 PM
Well, bummer. Sorry I couldn't help more.