Problem with text inputs

L

Leszek

Hi

I've got a proble because text inputs made by function are
outside frameset and below submit button.

What should I do to make it work properly?

Here is code

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
 
T

Thomas 'PointedEars' Lahn

Leszek said:
I've got a proble because text inputs made by function are
outside frameset and below submit button.
"frameset"?

What should I do to make it work properly?

1. Follow all the advice that you have already been given, especially:
2. do not post generating code, like PHP code, here; post what is
generated instead and
3. do not post the same nonsense twice if you have been corrected.


PointedEars
 
B

bwucke

Leszek napisal(a):
Hi

I've got a proble because text inputs made by function are
outside frameset and below submit button.

What should I do to make it work properly?

What do you WANT to do?
function zmiana(ile){
var formObj = document.forms["dane"];

gets the form object.
while(formObj.childNodes.length >3)

There's just one: <fieldset>. Nothing to remove right now. Why 3? There
will be always fieldset and two others left.

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

Wouldn't it be clearer, simpler and easier to write the above without
the (horrible) PHP code?

<select name="accperson" onChange="zmiana(this.value)">
<option value="0" selected >0</option>
<option value="1" selected >1</option>
<option value="2" selected >2</option>
<option value="3" selected >3</option>
<option value="4" selected >4</option>
<option value="5" selected >5</option>
</select>



What about this:
....
var formObj = document.getElementById(names);
....
while(formObj.childNodes.length>0)
....
</select>
<div id="names"></div>
....

Just create a container object (div) where you want extra content
added/removed. Personally I'd do this all with stylesheets (have all
the input fields there, hidden with display:none, and show them
depending on the choice, discard unused values through PHP.) this way
you'd avoid having to play with all the node creation.

One more thing:

pole.id="$name"+i;
pole.name="$name"+i;

this will cause trouble in PHP. Drop that $.
 
R

RobG

Leszek napisal(a):
[...]
function zmiana(ile){
var formObj = document.forms["dane"];


gets the form object.

while(formObj.childNodes.length >3)


There's just one: <fieldset>

There may also be some text nodes, depending on the browser and the
actual markup delivered to the browser.

e.g. Firefox and Safari will add two text nodes so that the form has 3
children if the markup is:

<form ... >
<fieldset ...>

<!-- more markup -->

</fieldset>
</form>


But will only have one child (the fieldset) if the markup is:

<form ... ><fieldset ...>

<!-- more markup -->

</fieldset></form>


I believe in Windows IE the form will have one child in either case,
IE 5.2 (Mac OS) thinks there's 3 and 1 respectively.

Wouldn't it be clearer, simpler and easier to write the above without
the (horrible) PHP code?

<select name="accperson" onChange="zmiana(this.value)">
<option value="0" selected >0</option>
<option value="1" selected >1</option>
<option value="2" selected >2</option>
<option value="3" selected >3</option>
<option value="4" selected >4</option>
<option value="5" selected >5</option>

I think you might have a copy/past problem - a single select should
only have one option selected by default. :)


[...]
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top