Closed Thread Icon

Preserved Topic: text forms (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8499" title="Pages that link to Preserved Topic: text forms (Page 1 of 1)" rel="nofollow" >Preserved Topic: text forms <span class="small">(Page 1 of 1)</span>\

 
Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 01-29-2003 16:33

Hi, I'm having trouble writing a script. It should fill out all fields same as the first one, like this:

window.document.formular.kunde1.value=window.document.formular.kunde0.value;
window.document.formular.kunde2.value=window.document.formular.kunde0.value;
window.document.formular.kunde3.value=window.document.formular.kunde0.value;

Now, the problem is, I don't know how many of these fields are displayed. I tried the following:

for (i=1;i<total;i++)
{
window.document.formular.kunde"+i+".value=window.document.formular.kunde0.value;
}

But of course it did not work. Anybody know how I could solve this problem?
Another Question. Why cant text-inputs be named name="kunde-1" for example, because I always got an error when I tried to access the values of those fields (or write in them)

Thanks!

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 01-29-2003 16:54

Instead of

window.document.formular.kunde"+i+".value=window.document.formular.kunde0.value;

use

window.document.formular["kunde"+i].value=window.document.formular.kunde0.value;

(when you need to access the property of an object by a string, you use the object["property"] syntax.)

"Why cant text-inputs be named name="kunde-1" for example, because I always got an error when I tried to access the values of those fields"

Because a minus sign in JavaScript does subtraction. So

document.myform.kunde-1.stuff

is read as

document.myform.kunde - 1.stuff

which makes no sense. =)

Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 01-29-2003 17:29

thanks... That worked fine.

But how can I address radiobuttons or checkboxes with javascript?

I have x radiobuttons
<input type="radio" class="checkbox" name="e1-0" value="1" checked>
<input type="radio" class="checkbox" name="e1-0" value="2">


<input type="radio" class="checkbox" name="e1-1" value="1">
<input type="radio" class="checkbox" name="e1-1" value="2" checked>

etc. How can I copy the status of the first radiobutton to the others? window.document.formname["e1-"+i].value didnt work.

any ideas?

[This message has been edited by Gweilo (edited 01-29-2003).]

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 01-29-2003 18:05

Accessing radio buttons via JavaScript is a bit more complicated as the buttons that belong to a group are stored in an array. You have to loop through the array to see which button is checked as explained here:

http://codepunk.hardwar.org.uk/ajs19.htm

Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 01-29-2003 18:55

Thanks for the link. I'm not trying to loop through the array, I'm trying to loop through multiple arrays.

if (window.document.formular["e1-0[0]"].checked == true)
window.document.formular["e1-"+i+"[0]"].checked = true;

Something like this, but it won't work. Any ideas how to solve this problem?



[This message has been edited by Gweilo (edited 01-29-2003).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 01-29-2003 19:14

Instead of

...document.formular["e1-0[0]"].checked

try

...document.formular["e1-0"][0].checked

(Only one property can be in the string when the [] method of accessing properties is used. Note that object["property"]["subproperty"]["yetanotherproperty"] is perfectly legal.)

Gweilo
Bipolar (III) Inmate

From: switzerland
Insane since: Sep 2002

posted posted 01-29-2003 20:18

Thanks a lot Slime!

« BackwardsOnwards »

Show Forum Drop Down Menu