Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Complete noob to Javascript - help with dropdown boxes

    Hi,
    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.

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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:

    document.getElementById('text1').style.display="none";
    the above completly removes it from the page. it still exsists butis removed and all other elements in the document will move accordingly.

    document.getElementById('text1').style.visibility="hidden";
    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.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    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?
    Thanks.

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    <input type=text id=t1>
    <input type=text id=t2>
    <input type=button value=calc onclick=calc()>
    <script type=text/javascript>
    function calc(){
    document.getElementById('t2').value=document.getElementById('t1').value-(-1);
    }
    </script>
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •