Topic: Error: document.form has no properties Pages that link to <a href="https://ozoneasylum.com/backlink?for=27669" title="Pages that link to Topic: Error: document.form has no properties" rel="nofollow" >Topic: Error: document.form has no properties\

 
Author Thread
Sirius
Obsessive-Compulsive (I) Inmate

From: Edmonton
Insane since: Feb 2003

IP logged posted posted 03-22-2006 03:54 Edit Quote

Hi all,

This is only a little problem I'm sure but I can't see it.

I get this error : document.form has no properties and my text field isn't modified.

code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>test</title>
<script type="text/javascript" language="javascript">
     <!--
	  function tossing()
	  {
	  toss = 0;
	  var toss = Math.round(20*Math.random());
	  document.dice_toss.dice.value = toss;
	  }
    //-->
</script>
</head>

<body>

<form id="dice_toss" action="toss_that(); return false;">

    Dice:

    <input id="dice" type="text" value=""/><br />

    <input type="button" onclick="return tossing()" value="Toss It Dude!"/><br />

    <input id="tossit" type="submit" value="Submit"/>

</form>

</body>
</html>



Cheers,

Patrick

(Edited by Sirius on 03-22-2006 04:03)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

IP logged posted posted 03-22-2006 05:41 Edit Quote

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.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

IP logged posted posted 03-22-2006 07:16 Edit Quote

document.dice_toss doesn't exist

you need document.forms.dice_form



.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 03-22-2006 07:17)

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

IP logged posted posted 03-22-2006 08:59 Edit Quote

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>

I think. My javascript is still pretty rusty.


Justice 4 Pat Richard

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

IP logged posted posted 03-22-2006 13:45 Edit Quote

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.

--
var Liorean = {
abode: "http://codingforums.com/",
profile: "http://codingforums.com/member.php?u=5798"};

(Edited by liorean on 03-22-2006 13:50)

Sirius
Obsessive-Compulsive (I) Inmate

From: Edmonton
Insane since: Feb 2003

IP logged posted posted 03-26-2006 04:14 Edit Quote

thanks all and thanks Liorean for the informations...really appreciated.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 03-26-2006 11:41 Edit Quote

Hey liorean,

that's a nice overview.
Would you mind adding it to the faq?
Possibly below DHTML/JavaScript...

If you like, you could also add your name to Give us your permission to archive things in the FAQ.

Thanks
so long,

->Tyberius Prime

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

IP logged posted posted 04-06-2006 12:27 Edit Quote

Oh before I forget about this thread: I've added permission to archive things.

Haven't written it into a point in the FAQ though.

--
var Liorean = {
abode: "http://liorean.web-graphics.com/",
profile: "http://codingforums.com/member.php?u=5798"};

sabapc
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Apr 2006

IP logged posted posted 04-13-2006 19:14 Edit Quote

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'll appreciate any help.
Thanks.

sabapc
Obsessive-Compulsive (I) Inmate

From:
Insane since: Apr 2006

IP logged posted posted 04-13-2006 19:32 Edit Quote

Well... I fixed it, by having previously generated the form
with the structure (4 fields), and then calling the function

"submitForm(value1,value2,value3,value4)"

So the form is now "something" like this:

code:
<form name="my_uniq_form">
  <input .... name="field1" value="">
  <input .... name="field2" value="">
  <input .... name="field3" value="">
  <input .... name="field4" value="">
</form>



And then, the submit javascript function sets the values and submits.
It works... but I still don't know why the other way didn't work.

ab_wmu
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jul 2007

IP logged posted posted 07-09-2007 18:24 Edit Quote

Hi,

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;
}

for( i=0; i< selectedqslen ; i++)
{
alert(selectedqslen);
selectedqs.options[i].selected = true ;
}
alert(formname);
var sform = document.getElementById(formname);
//alert(document.Id('makeqset'));
//sform.submit();
document.forms['makeqset'].submit();
}

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.

argo navis
Nervous Wreck (II) Inmate

From:
Insane since: Jul 2007

IP logged posted posted 07-09-2007 18:40 Edit Quote

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[...

And then, dunno.

ab_wmu
Obsessive-Compulsive (I) Inmate

From:
Insane since: Jul 2007

IP logged posted posted 07-09-2007 18:46 Edit Quote

I am sorry I actually had an alert

alert(sform)

and this returns a null
and the mozilla error console has this error with path.
Error: document.forms.makeqset has no properties

ab_wmu
Nervous Wreck (II) Inmate

From:
Insane since: Jul 2007

IP logged posted posted 07-09-2007 21:55 Edit Quote

Hey,

I was able to figure out the problem ... thanx a lot

argo navis
Nervous Wreck (II) Inmate

From:
Insane since: Jul 2007

IP logged posted posted 07-11-2007 10:17 Edit Quote

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.

tftd
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Sep 2007

IP logged posted posted 09-27-2007 17:21 Edit Quote

Hi there,

I'm having this problem:
document.forms.input has no properties
document.forms["input"].action = "index.php?action=reg";

Code:

<script type="text/javascript">
alert("Email address already in use !");
function submit()
{
document.forms["input"].action = "index.php?action=reg";
return document.forms["input"].submit();
}
</script>
<form name="input" method="post">
<input type="hidden" name="uname_eng" value="'.$uname.'">
<input type="hidden" name="dname_arb" value="'.$dname.'">
<input type="hidden" name="email" value="'.$email.'">
<script type="text/javascript">
submit();
</script>
</form>



Any suggestions ?


Thanks in advance !

jainanki
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Dec 2007

IP logged posted posted 12-11-2007 16:22 Edit Quote

Hi,

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.

Thanks,
ankit

Blaise
Paranoid (IV) Inmate

From: London
Insane since: Jun 2003

IP logged posted posted 12-11-2007 17:31 Edit Quote

First off, you should never nest forms!

This may be the beginning of your problem

jainanki
Obsessive-Compulsive (I) Inmate

From: Philadelphia, PA.
Insane since: Dec 2007

IP logged posted posted 12-11-2007 22:18 Edit Quote

Thanks Blaise. I figured out the problem after some head banging.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu