That's a weird error to get, considering your script doesn't actually contain the text "document.form" anywhere.
The only problem I can see is that the function toss_that() doesn't exist, yet you try to call it. Also, I don't think action="..." is a safe place to put script; I think you want onsubmit="..." instead.
Well... the form itself requires a 'name' attribute in order to be valid, and then the javascript needs to reference document.forms.<value of the form's 'name' attribute>
Some things:
- Compliant browsers use id and then name in the forms collection.
- Traditionally browsers used name, and some browsers haven't yet started supporting id only.
- There are two good ways of doing it.
One way is to use document.getElementById('dice_toss'); the other way is to use document.forms['dice_toss'] that the form is given that name and just not id.
In any ways, you need to understand that name means different things depending on what elements it's used on, and it is treated differently in different situations.
HTML/XHTML distinctions:
- On form controls: The name attribute is the form control name, in other words it is the label that will be given to the control value when sending it to the server. Checkbox and radio controls may share names, but all other controls must be unique *within the form*. The id attribute on the hand must be a unique identifier *within the document*. The name attribute allows several charachters that the id attribute does not, but that's okay since they have entirely different purposes and use. There is no need to have the same id and name value here. The id attribute is made for client side handling while the name attribute is for the server when recieving the form. Form controls that the user can change the state of, as well as hidden controls, MUST have a name attribute. (As per the HTML4.01 spec.)
- On non-form-control, non-frame elements: name and id share namespace and are both treated as if they were ids, each element may only be given one unique identifier and thus they may not contain different values. The name attribute allows some characters that the id attribute does not, these should be avoided. This category includes the form element.
- and I'll skip explaining the frame elements...
DOM/JavaScript distinctions:
- document.form_name access is proprietary. It's ubiquitous but discouraged and should be avoided.
- document.forms['form_name'] syntax is on the other hand DOM0 and W3C DOM and is recommended. The only caveeat is that some browsers haven't started supporting id for form names.
- document.getElementById('fom_name') is supported by all browsers, and should work in all browsers as long as you use the id attribute for the form name.
- document.getElementsByName is horribly broken and implemented differently in ALL browsers to date (Try it with all possible types of id/name combos in a document and html/xhtml/xml content types and you'll see a bloody mess of different behaviors, sometimes different in different versions of the same browser.). Not to speak of the fact it's intended only for form control names, but that distinction doesn't seem to take place in browsers.
Hi... hi have a similar problem, but couldn't solve it by reading this.
I have several forms... something like this:
code:
<form method='post' id='form_d431edd4e824b919878c94cca014324a' style='display: inline' action='index.php'>
<input type='hidden' name='pa' value='1'>
<input type='hidden' name='sec' value='29'>
<input type='hidden' name='doc_id' value='16'>
<input type='hidden' name='backurl' value='/milenio/index.php?pa=1&sec=25'>
</form>
<a href='javascript:submitFormById("form_d431edd4e824b919878c94cca014324a")'>Editar datos de este documento</a>
....
....
<form method='post' id='form_53db6cc665df1ea68569c1381a05cb5d' style='display: inline' action='index.php'>
<input type='hidden' name='pa' value='1'>
<input type='hidden' name='sec' value='29'>
<input type='hidden' name='doc_id' value='17'>
<input type='hidden' name='backurl' value='/milenio/index.php?pa=1&sec=25'>
</form>
<a href='javascript:submitFormById("form_53db6cc665df1ea68569c1381a05cb5d")'>Editar datos de este documento</a>
So, all this forms are in different <div>s (all of the divs are initially hidden (display: none), by a click in another link, each of this links is displayed.
The thing is that, I can click all the forms but the first. If I click any link that is not the first of the list, the form is submited. If I click the first link (the link that submits the first form) I get "document.getElementById(formid) has no properties".
My javascript method for submiting is:
code:
function submitFormById(formid) {
document.getElementById(formid).submit();
}
All this forms are generated by a php script (for a list of documents)... and I use md5 ids so they can submit independently.
I don't know why I can submit any of the forms but the first. Does the fact that I'm enclosing every form in a <div style='display: none'> affect in any way?
I have a function
function savechanges(formname)
{
var allqs = document.getElementById("allqs");
var selectedqs = document.getElementById("selectedqs");
selectedqslen = selectedqs.length;
// Check if the inviteelist is not empty.
if(selectedqslen <=0)
{
alert(" Please select a quiz question before Saving");
return 0;
}
Which takes selected values from select multiple and submits it.
I tried a lot of methods suggested by this form but in vain.
"alert(document.Id('makeqset'));"
line return a NULL. Can you please help me out with this.
well, it's alert(document.getElementById('formid')); to begin.
Then, I would suggest a thread per question.
And then, I would suggest document.getElementsByTagName("form")['formid'].submit(); instead of document.forms[...
Good, always happy to help. I was about to copy paste your code and try for myself, but...
If you don't mind explaining what went wrong, it never hurts.
I read this post, tried things but still am not able to fix the problem in my code.
I have a form nested in another form, which is in turn into a div.
Now I am trying to submit this form. I have been successful in accessing the test fields into that form, an changing them. But when I try to submit the form, it gives me error.
When I try
document.getElementById['myForm'].submit();
it gives me this error:
document.getElementById.myForm has no properties
document.forms['myForm'].submit();
it gives me this error:
document.forms.myForm has no properties
Any help would be highly appreciated.
This is my javascript:
<script type="text/javascript">
function launch()
{
var frm = document.getElementById("myForm");
var srcTxt = document.getElementById("dirName");
var dstTxt = document.getElementById("name");
dstTxt.value = '/xml' + '/' + srcTxt.value;
alert(frm); // Gives null
document.forms['myForm'].submit();
}
</script>
I an calling launch() on onclick() event of a button in the form.