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 8 of 8
  1. #1
    Banned
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Making a search form where inputs only appear on certain selection

    I want to make a search form where inputs only appear if a certain selection has been made. For example the user selects "Green" then the input "X" appears, and if the user clicks "Black" then input "Y" appears. How can this be done? If so, can someone give me a basic example in code that I can use to copy off?

  • #2
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by Kolusion View Post
    If so, can someone give me a basic example in code that I can use to copy off?
    yes it can be done very easily using javascript but afaik this is not a free coding service. Unless a generous person stops by, I think you'll have a better chance if you post your attempt and someone(s) can then help you with it.

    If you want someone to do it for you to then just copy, then it sounds like a homework exercise you can't do on your own.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,629
    Thanks
    6
    Thanked 1,002 Times in 975 Posts
    webdev1958 is right, even though he/she is very direct in expressing it. You’ll have to use JavaScript to check if a certain selection has been made and enable/show the appropirate input. But if you want something to copy then go on a website where such a feature exists and copy it from there, don’t request something here without proving any own attempt whatsoever – this is what webdev1958 was trying to point out to you. You may be lucky and someone gomes by and provides you with a hint on how to approach this.

    Now, refrain from re-posting this in the JS forum, I’m gonna move it there.

  • #4
    Banned
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    "go on a website where such a feature exists and copy it from there"

    You got a website?

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by VIPStephan View Post
    to you. You may be lucky and someone gomes by and provides you with a hint on how to approach this.
    I am not sure that I like your attitude, but I will give you the benefit of the doubt. This is an adult forum for professional people, not Facebook. Please do not abuse it. One sure way to find yourself ignored here is to try being a smart-mouth.

    This is an outline example of what you are looking for. But it contains a couple of deliberate mistakes for you to fix. If you can't fix them, we will know that this was homework.

    Code:
    <form id = "mtform">
    <select id = "mysel" onchange = "show()" >
    <option value= "">Choose a color...</option>
    <option value = "Green">Green</option>
    <option value = "Black">Black</option>
    </select>
    <br><br>
    <span id = "xinp" style="display:none">X <input type = "text" id = "txt1"></span>
    <span id = "yinp" style="display:none">Y <input type = "text" id = "txt1"></span>
    </form>
    
    <script type = "text/javascript">
    function show() {
    document.getElementById("xinp").style.display="none";
    document.getElementById("yinp").style.display="none";
    var val = document.getElementById("myselt").value;
    if (val != "") {
    switch(val) {
    case "Green":document.getElementById("xinp").style.display=block; break;
    case "Black":document.getElementById("yinp").style.display=block; break;
    }
    }
    }
    
    </script>

    This year, if you want to win the Premiership, you are going to have to finish above Manchester United. - Commentator, Talksport
    Last edited by Philip M; 08-22-2011 at 03:43 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,629
    Thanks
    6
    Thanked 1,002 Times in 975 Posts
    Quote Originally Posted by webdev1958 View Post
    and you still can't spell or you haven't the courage to say what you mean and instead hide behind *'s - take your pick
    Just FYI: Don’t you think you’re smarter, the OP is insulting you alright. This is just the automatic bad word filter which replaces bad words with askterisks.

  • #7
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    I'm not sure there is a bad word detector because it didn't filter out the c word which I imagine should have been filtered out.

  • #8
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    A simple web search provides plenty of examples. You even got one in this thread (although it's true that CF is not a free coding service), and you answered that one with an insult, so I suppose you don't want the help after all.

    This thread is now locked.


  •  

    Posting Permissions

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