Reputation: 511
I´m trying to reference a submit button:
<input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
Tried this:
var submit_btn = $('submit');
and also with document.getElementByID('submit')
.
But it always evaluates to null
..
Also tried to loop all form elements to reach the button as lastChild
but the result is allways null
. Is this a known bug?
Also, when I try to reference the form element by id, the result is also null
..
Upvotes: 0
Views: 1368
Reputation: 8550
Just ran into a similar IE8 problem. Most of the input elements were null inside a form when accessed via JS. Here's the markup:
<p>
<form styleId="districtReportForm" method="post" onsubmit="return false;">
<input name="reportType" value="0" type="hidden">
<input name="districtId" value="30001176" type="hidden">
Worked fine in everything but IE8. In IE8, after 'reportType' there were no elements inside the form. For example, after getting the form by ID, form.districtId
was null.
So I ran:
dojo.byId('districtReportForm').innerHTML
To see what IE thought was there, and it reported:
"<INPUT name=reportType value=0 type=hidden> </P>"
Apparently IE had decided to close the opening <p>
for me (admittedily it wasn't properly closed). Removing the paragraph element fixed this.
Upvotes: 0
Reputation: 413720
I bet IE just doesn't like the value "submit" for the "id" property of the element. Remember that IE wants to use the "id" value as a property name on the "window" object, and it might consider "submit" to be a reserved word. I know you say you can't change the value. If you're using jQuery, try$('input[name=submit]')
Upvotes: 2
Reputation: 3634
Try:
$("input#submit");
or:
$("input[type='submit']");
Also, it's considered poor practice to give ID's such as "Submit" -- be a bit more descriptive like: <input id="SubmitRegistration">
Remember to use the # selector to reference ID's -- you didn't in your statement above.
Also, remember to place your jQuery inside a $(document).ready(function() {});
to make sure it runs after the dom's loaded.
Upvotes: 0
Reputation: 19943
I assume the dollar function is the Prototype library? If not, in JQuery, the invocation should be $('#submit')
.
Or, are you trying this straight from within a <script>
tag? You may have to wrap the code in an onLoad callback. If you do not, your browser may execute the script before the page has been fully loaded, and your element could still be missing from the DOM. Examples:
For Prototype:
Event.observe(window, 'load', function() {
// your code
});
For JQuery:
$(document).ready(function() {
// your code
});
Upvotes: 0
Reputation: 449415
submit
on the page?Upvotes: 0