DOM addity

T

Tim Slattery

I just ran into a situation that I wonder about. I have this HTML
file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>form submit testing</title>
<script type="text/javascript">
function subform(code)
{
document.getElementsByName("ephReason1")[0].value=code;
document.getElementById("finishForm").submit();
}
</script>
</head>

<body>
<h1>Form testing</h1>
here's the hidden form:
<form name="EntryFormBean" method="post" action="/CES/finalEdit.do"
id="finishForm">
<div>
<input type="hidden" name="respondent" value="156078706" />
<input type="hidden" name="month" value="" />
<input type="hidden" name="year" value="" />
<input type="hidden" name="ephReason1" value="" />
<input type="submit" name="submit" value="Submit Data to BLS"
class="submit" title="Submit Data to BLS"
alt="Submit Data to BLS" />
</div>
</form>
Here are the buttons:<br/>
<input type="submit" class="submit" onclick="subform('5')"
alt="Identical data is correct" title="Identical data is correct"
value="Yes"/>&nbsp;&nbsp;&nbsp;
<input type="submit" class="submit"
onclick="document.getElementById('edit1').submit();"
alt="Identical data is wrong" title="Identical data is wrong"
value="No"/>
</body>
</html>


Notice the "name" attribute on the "<input type="submit"...>. With
that attribute in place, the "subform" Javascript wouldn't work.
Apparently when the script tries to call the form's "submit" method,
it gets the "submit" button instead, and can't figure out why I'm
treating it like a method.

I got around it by simply deleting the "name" property from the
"submit" button. But I wonder whether there is something I might have
done in the javascript code to get the "submit" method instead of the
button?
 
R

RobG

Tim said:
I just ran into a situation that I wonder about. I have this HTML
file: [...]
<script type="text/javascript">
function subform(code)
{
document.getElementsByName("ephReason1")[0].value=code;
document.getElementById("finishForm").submit();
} [...]
<form name="EntryFormBean" method="post" action="/CES/finalEdit.do"
id="finishForm">
<div>
<input type="hidden" name="respondent" value="156078706" />
<input type="hidden" name="month" value="" />
<input type="hidden" name="year" value="" />
<input type="hidden" name="ephReason1" value="" />
<input type="submit" name="submit" value="Submit Data to BLS"
class="submit" title="Submit Data to BLS"
alt="Submit Data to BLS" />
</div>
</form> [...]

Notice the "name" attribute on the "<input type="submit"...>. With
that attribute in place, the "subform" Javascript wouldn't work.
Apparently when the script tries to call the form's "submit" method,
it gets the "submit" button instead, and can't figure out why I'm
treating it like a method.

Because named controls are added as properties of the form DOM object,
so an element named 'submit' will mask the form's submit method.

I got around it by simply deleting the "name" property from the
"submit" button. But I wonder whether there is something I might have
done in the javascript code to get the "submit" method instead of the
button?

The only reliable solution is to not have a control named 'submit' in
the form.

The only reason to name a submit button is if you have more than one
on a page or within a form and you want to know which one was pressed.
 
T

Tim Slattery

RobG said:
The only reason to name a submit button is if you have more than one
on a page or within a form and you want to know which one was pressed.

I agree with that. I just wondered if there was a "methods" collection
or something like that which would allow access to the hidden method.
Maybe not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top