Hi.
I wrote a script:
function zmiana(ile){
while(document.getElementById('accomp').childNodes .length>1){
ostatni=document.getElementById('document.dane.acc omp').lastChild;
document.getElementById('document.dane.accomp').re moveChild(ostatni);
}
for (i=1;i<=ile;i++){
pole=document.createElement("BR");
document.getElementById('accomp').appendChild(pole );
a=document.createTextNode("Name of accompanying person #"+i+" ")
document.getElementById('accomp').appendChild(a);
dane.style.fontWeight='bold';
pole=document.createElement("input");
pole.type = "text";
pole.size="40";
pole.id="$name"+i;
pole.name="$name"+i;
document.getElementById('accomp').appendChild(pole );
}
}
it's working with a form:
<form name="accomp">
// instructions
</form>
But now i want to put my form into another form:
<form name="dane">
<form name="accomp">
// instructions
</form>
<form>
What should i change in my function to make it working with my new form?
I tried putting 'dane.accomp' instead of 'accomp' but i'm getting a message
that "object is required"
when I put 'dane' instead of 'accomp' I didin't get any errors but it
didin't work correctly.
What's wrong?
Thanks for any ideas.
Leszek 6 6292
Leszek wrote: ostatni=document.getElementById('document.dane.acc omp').lastChild; document.getElementById('document.dane.accomp').re moveChild(ostatni);
The argument you have passed to getElementById is incorrect. It should
be replaced with the actual id:
ostatni = document.getElementById("accomp").lastChild;
document.getElementById("accomp").removeChild(osta tni);
On a side note, it would also be more efficient if you did something
like the following:
var formObj = document.getElementById("accomp");
while(formObj.childNodes.length > 1)
{
formObj.removeChild(formObj.lastChild);
}
dane.style.fontWeight='bold';
You are incorrectly referencing 'dane'. You could potentially fix it
like so:
document.getElementById("dane").style.fontWeight = "bold";
pole.id="$name"+i; pole.name="$name"+i;
IIRC, id and name can only start with any character a-z, A-Z, and
underscore.
<form name="dane"> <form name="accomp">
// instructions
</form> <form>
There can be several forms in a single document, but the FORM element
can't be nested. Otherwise you'll have invalid html.
Leszek wrote:
<snip> But now i want to put my form into another form:
<snip>
Forms may not contain forms.
Richard.
Leszek wrote: function zmiana(ile){ while(document.getElementById('accomp').childNodes .length>1){
Care to test for methods before you call them?
<URL:http://pointedears.de/scripts/test/whatami>
ostatni=document.getElementById('document.dane.acc omp').lastChild;
[1]^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[2]
[1] Undeclared global variable. Use the `var' keyword.
[2] There is no ID `document.dane' or `document.dane.accomp'.
And ever heard of the `document.forms' collection?
document.getElementById('document.dane.accomp').re moveChild(ostatni); } for (i=1;i<=ile;i++){
^
Another undeclared global variable.
pole=document.createElement("BR");
^^^^
And another one. And calling another method without feature-testing it
before.
document.getElementById('accomp').appendChild(pole );
And again.
a=document.createTextNode("Name of accompanying person #"+i+" ")
^ ^^^^^^^^^^^^^^^^^^^^^^^
And again.
document.getElementById('accomp').appendChild(a);
dane.style.fontWeight='bold';
pole=document.createElement("input"); pole.type = "text";
If document.createElement() returned not an object, this unguarded statement
would be a ReferenceError. Besides, last time I checked type="text" was
the default.
<URL:http://www.w3.org/TR/html4/interact/forms.html#h-17.4>
pole.size="40"; pole.id="$name"+i;
In case that is assigning the ID as-is: IDs must not start with `$', they
must start with an ASCII latin letter.
<URL:http:///www.w3.org/TR/html4/types.html#type-id>
In case `$name' is an attempt at including the value of a client-side
variable: there is no variable expansion in double quotes in JS/ECMAScript;
you will have to do string concatenation or joining of Array elements.
In case `$name' is a reference to a server-side variable (say from PHP),
you should have posted what the user agent gets (View Source), since you
are manipulating its DOM.
pole.name="$name"+i;
The same goes for NAME values. However, the `name' attribute of `input'
elements is of type _CDATA_ where `$' is allowed as first character; so
it is also allowed for the `name' property of HTMLInputElement objects
representing it.
document.getElementById('accomp').appendChild(pole ); } } it's working with a form:
If that really worked, this would be merely a highly unlikely coincidence.
<URL:http://jibbering.com/faq/#FAQ4_43>
<form name="accomp">
The `action' attribute is missing.
// instructions
Those are not instructions, HTML is not a programming language.
</form>
But now i want to put my form into another form: <form name="dane"> <form name="accomp">
// instructions
</form> <form>
Since that is not Valid HTML, that is not going to work.
<URL:http://validator.w3.org/>
<URL:http://www.w3.org/TR/html4/interact/forms.html#h-17.3> (note
the "-(FORM)" condition for the content model of the `form' element)
What should i change in my function to make it working with my new form?
You cannot.
[...] What's wrong?
Better ask what is right, the answer to that would have been shorter.
Please RTFM before you ever code, that saves many people much time,
including you.
PointedEars
web.dev wrote: Leszek wrote: [...] On a side note, it would also be more efficient if you did something like the following:
var formObj = document.getElementById("accomp");
That would assume that "accomp" is an ID. It is not, it is a name.
Anyway,
var formObj = document.forms["accomp"];
is more reliable. Never use IDs and document.getElementById() if you
do not have to.
while(formObj.childNodes.length > 1) { formObj.removeChild(formObj.lastChild); }
dane.style.fontWeight='bold';
You are incorrectly referencing 'dane'. You could potentially fix it like so:
document.getElementById("dane").style.fontWeight = "bold";
document.forms["dane"].style.fontWeight = "bold";
is far more compatible, yet still error-prone because of the Reference
Worm[tm] it represents and the proprietary properties it uses. pole.id="$name"+i; pole.name="$name"+i;
IIRC, id and name can only start with any character a-z, A-Z, and underscore.
You are recalling wrong :) ID and NAME values can only start with any
ASCII latin letter, that is a-z and A-Z. However, that does not apply
to the `name' attribute/property, since the attribute type is CDATA (and
not NAME) and so it and its representing property may have _any_ (string)
value, provided for the attribute value to not contain references to
undeclared entities.
PointedEars
Thomas 'PointedEars' Lahn wrote: web.dev wrote: Leszek wrote: pole.id="$name"+i; pole.name="$name"+i; IIRC, id and name can only start with any character a-z, A-Z, and underscore.
You are recalling wrong :) ID and NAME values can only start with any ASCII latin letter, that is a-z and A-Z. However, that does not apply to the `name' attribute/property
of _`input'_ elements/_HTMLInputElement_ objects (because it does apply to
the `name' attribute/property of `meta' elements/HTMLMetaElement objects
and `a' elements/HTMLAnchorElement objects)
since the attribute type is CDATA (and not NAME) [...]
PointedEars
Thomas 'PointedEars' Lahn wrote: web.dev wrote: Leszek wrote: pole.id="$name"+i; pole.name="$name"+i; IIRC, id and name can only start with any character a-z, A-Z, and underscore.
You are recalling wrong :) ID and NAME values can only start with any ASCII latin letter, that is a-z and A-Z. However, that does not apply to the `name' attribute/property
of _`input'_ elements/_HTMLInputElement_ objects (because it does apply to
the `name' attribute/property of `meta' elements/HTMLMetaElement objects)
since the attribute type is CDATA (and not NAME) [...]
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: L Major |
last post by:
Hi
Unfortunately, I am limited to using tables for part of my current
project. I have a form that spans across a number of TR and TD in the
shape of checkboxes.
Doctype is XHTML 1.0...
|
by: Markus Ernst |
last post by:
Hi
I have a validation problem with a form and nested divs. I understand what
the problem is, but I don't see how to fix it. This is my normal page
structure, and it validates:
<!DOCTYPE HTML...
|
by: Pete Wilson |
last post by:
Hi folks --
The page at
http://www.pwilson.net/submit-demo.html
will not validate. The validator at http://validator.w3.org tells me I
can't have an input inside a form.
Would some kind...
|
by: Matthew Louden |
last post by:
It happend to me more than once. When I create web controls or move the
positions in VS.NET, I encountered the following run-time errors: It doesn't
matter what controls I create, the following...
|
by: Eric |
last post by:
Couple of general webform questions. Most are about html code
created/managed by the editor. I work in GridLayout Mode.
1. Is there a reference or guideline for how the html should appear
when...
|
by: Neo Geshel |
last post by:
After pouring over about a dozen sites that clearly dealt with ClientID
all by itself, I came to the realization that about 2/3+ of them were
doing it wrong. It is indeed impossible to grab the...
|
by: Anja |
last post by:
Hi everyone,
I have a sub form that references a query to get the results. However,
what I want to do is filter the results further based on a certain
criteria. How can I tell the sub form to...
|
by: pbd22 |
last post by:
hi.
could somebody tell me, when uploading a file, i know the form where
the upload component is must
have enctype=multipart/form-data but, is the same true for the form
with the server code to...
|
by: shapper |
last post by:
Hello,
I am creating a form that includes a few JQuery scripts and TinyMCE
Editor:
http://www.27lamps.com/Beta/Form/Form.html
I am having a few problems with my CSS:
1. Restyling the Select
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |