PDA

View Full Version : dynamic forms


bartezz
11-09-2002, 05:33 PM
Hi, i'm almost sick of searching a solution on my problem. hopefully you can help.
To explain my problem, i will use a very little form. In this form i have a input box 'age' (text) and a selection field 'transport' with options (by walk, by bicycle, by moped, by car,... ).
Suppose you have to enter your age and the way you travel yourself.
When you enter age: 14 , the options moped and car should be immediatly unselectable (or invisible, doesn't matter) because you can not drive a car of moped at that age.
I want something like this, but without refreshing the page. how should i do it?

THX!

Mr J
11-09-2002, 08:19 PM
Is this the kind of thing you are on about.

This is only a draft




<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<form name="f1">
<input type=text name=t1 size=3 maxlength=3 onclick=" document.f1.t1.select()">
<select name="s1" size=5 style="width:100">
</select>
<input type="button" value="button1" onclick="test();">
</form>

<script>
which=new Array()
which[which.length]=new Array("Walk","Bicycle")
which[which.length]=new Array("Walk","Bicycle","Moped")
which[which.length]=new Array("Walk","Bicycle","Moped","Car")

n=0
function test(){
for (i = document.f1.s1.options.length; i != 0; i--) {
document.f1.s1.options[i - 1] = null;
}

if(document.f1.t1.value<16){
n=0
for(o=0;o<which[n].length;o++){
eval(document.f1.s1.options[o] = new Option(which[n][o]));
}
}

if(document.f1.t1.value>15&&document.f1.t1.value<18){
n=1
for(o=0;o<which[n].length;o++){
eval(document.f1.s1.options[o] = new Option(which[n][o]));
}
}

if(document.f1.t1.value>17){
n=2
for(o=0;o<which[n].length;o++){
eval(document.f1.s1.options[o] = new Option(which[n][o]));
}
}

}
</script>

Ages to enter:
<P>0 to 15<br>
16 to 17<br>
18 +
</BODY>
</HTML>