Select inside a form

L

Leszek

function zmiana(ile){
var formObj = document.getElementById("dane").
while(formObj.childNodes.length > 3)
{
formObj.removeChild(formObj.lastChild);
}
for (i=1;i<=ile;i++){
pole=document.createElement("BR");
formObj.appendChild(pole);

a=document.createTextNode("Name of accompanying person #"+i+" ")
formObj.appendChild(a);

formObj.style.fontWeight='bold';

pole=document.createElement("input");
pole.type = "text";
pole.size="40";
pole.id="name"+i;
pole.name="name"+i;
formObj.appendChild(pole);
}
}

What should be in changed in line:

var formObj = document.getElementById("dane").

to make it work with something like this

<form name="dane">
<select name="accomp">

//instructions

</select>
</form>

Thanks.
Leszek
 
T

Thomas 'PointedEars' Lahn

Leszek said:

You'll probably bite the carpet when you have read the reponses to your
other posting because they address the problems with that code.
What should be in changed in line:

var formObj = document.getElementById("dane").

to make it work with something like this

<form name="dane">

Again, the `action' attribute is missing. The above is invalid HTML.
<select name="accomp">

//instructions

Again, HTML is not a programming language; it is a markup language.
</select>
</form>

var formObj = document.forms["dane"];

because there is no _ID_ `dane', there is a _name_.

However, you should rather try to pass a reference to the HTMLSelectElement
object (and then use its `form' property) or to the HTMLFormElement, with
`this'.


PointedEars
 
L

Leszek

Uzytkownik "Thomas 'PointedEars' Lahn said:
var formObj = document.forms["dane"];
I tried with this and it works but the text inputs made by function are now
outside frameset and below submit button
Here is code again:

function zmiana(ile){
var formObj = document.forms["dane"];
while(formObj.childNodes.length >3)
{
formObj.removeChild(formObj.lastChild);
}
for (i=1;i<=ile;i++){
pole=document.createElement("BR");
formObj.appendChild(pole);

a=document.createTextNode("Name of accompanying person #"+i+" ")
formObj.appendChild(a);

formObj.elements.style.fontWeight='bold';

pole=document.createElement("input");
pole.type = "text";
pole.size="40";
pole.id="$name"+i;
pole.name="$name"+i;
formObj.appendChild(pole);
}
}

<form name="dane" action="uzytkownik.php" method.post>
<fieldset>

<select name="accperson" onChange="zmiana(this.value)">
<?php
$accperson=0;
echo "<option value=\"$accperson\" selected >$accperson</option> \n";
for ($accperson=1;$accperson<=5;$accperson++){
echo "<option value=\"$accperson\">$accperson </option>\n";
}
?>
</select>
<p align="center">
<input type="submit" value="Wyslij dane" />
</p>
</fieldset>
</form0
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top