View Full Version : Complete noob to Javascript - help with dropdown boxes

10-30-2006, 04:33 PM
I have a web page written in ASP. I have a form & on it there is a dropdown box which allows the user to select a time frequency (year, month etc). I then have 4 input boxes:

input1 STARTA
input2 STARTB
input3 ENDA
input4 END b

that I need completing BUT depending on what the user selects in the dropdown box determines which input boxes become active.

For example, if the user selects the frequency of year I only want input1 & input 3 to be shown / active. This would allow the user to enter '2006' into input1, I could then automatically calculate the value for input2.

I've done a bit of 'googling' & the 'getElement' code keeps cropping up but I've no idea how to use it!?!?!?

Any help would be much appreciated.

10-30-2006, 04:49 PM
ok say you have 3 input boxes and you want to use getElementById....
create the input boxes like such:

<input type=text id=text1>
<input type=text id=text2>
<input type=text id=text3>

then when wanting to change, from what i am assuming, the display of the input box do as so:

the above completly removes it from the page. it still exsists butis removed and all other elements in the document will move accordingly.

this will just make the text box invisible, but not remove it from the document. all other elements will stay where they are.

hope this helps explain it for you.

if you need help incorporating it into a working script let me know, I will be glad to assist.

10-31-2006, 12:39 PM
Thanks for the help already given. I now need to take this a step further.

I have used the code as given previousley so I know have my form items hidden / disabled according to the selection in my drop down box.

What I need now is if the user selects a time frequency where it requires a start I want the end to automatically appear. So if the user enters 2006 I want 2007 to appear.

So if I have input box1 I want input box 2 to automatically calculate the value from input box1 +1.

Can anyone help?

10-31-2006, 05:42 PM
<input type=text id=t1>
<input type=text id=t2>
<input type=button value=calc onclick=calc()>
<script type=text/javascript>
function calc(){