E
Erik Jälevik
I'm trying to understand the difference between using JavaScript in XML and
XHTML. I have a valid XHTML file with a form and some JavaScript. If I save
it as a .html file (this is under Windows), it all works fine, but if I save
it as a .xml file, the script can no longer reference the form.
In the code extract below, when run as xml in Mozilla throws an error on the
line trying to access tf.fname.value saying "tf has no properties". Why is
this?
<script type="text/javascript">
function validate() {
tf = document.taxform;
// Check that required fields are not empty
if (tf.fname.value == "" ||
tf.sname.value == "") {
// do stuff
}
</script>
....
<form
id="taxform"
action="http://teachwww.cogs.susx.ac.uk:8080/egj20/servlet/TaxReturnServlet"
method="post"
onsubmit="return validate()">
<p>
<label for="fname" class="required">First name:</label>
<input id="fname" name="fname" type="text" size="40" maxlength="40" />
</p>
....
</form>
XHTML. I have a valid XHTML file with a form and some JavaScript. If I save
it as a .html file (this is under Windows), it all works fine, but if I save
it as a .xml file, the script can no longer reference the form.
In the code extract below, when run as xml in Mozilla throws an error on the
line trying to access tf.fname.value saying "tf has no properties". Why is
this?
<script type="text/javascript">
function validate() {
tf = document.taxform;
// Check that required fields are not empty
if (tf.fname.value == "" ||
tf.sname.value == "") {
// do stuff
}
</script>
....
<form
id="taxform"
action="http://teachwww.cogs.susx.ac.uk:8080/egj20/servlet/TaxReturnServlet"
method="post"
onsubmit="return validate()">
<p>
<label for="fname" class="required">First name:</label>
<input id="fname" name="fname" type="text" size="40" maxlength="40" />
</p>
....
</form>