By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Select inside a form

P: n/a
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


Dec 28 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Leszek wrote:
[...]
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
Dec 28 '05 #2

P: n/a

Uzytkownik "Thomas 'PointedEars' Lahn" <Po*********@web.de> napisal w
wiadomosci news:11*****************@PointedEars.de...

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
Dec 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.