How to use Bootstrap dropdown as an HTML form – BeNice Nov 16 '15 at 18:43

  • Ok, I updated the link to the fiddle. You can listen for the click on the drop down selection, then you can do whatever you want with the selection that was made. – Cory Nov 16 '15 at 22:24
  • Cory - first - fantastic. Didn't think I could get the info into the form and then - voila! - I found this http://stackoverflow.com/questions/17809056/how-to-add-additional-fields-to-form-before-submit and. with a bit of hacking got the thing to work! I am amazed and HUGELY in your debt. – BeNice Nov 17 '15 at 07:35
  • One last question. Am I right in thinking that jQuery/JS variables cannot be: `aaa-bbb`? It seems a hyphen cost me 30 mins. I could not find a reference to acceptable variable formats. – BeNice Nov 17 '15 at 08:04
  • Yes, see here for JS variable name rules http://www.w3schools.com/js/js_variables.asp – Cory Nov 17 '15 at 13:18
  • 4

    Maybe this is what you wanted..:D

    function dropdownMenu1565Set(val){
     if(val.innerHTML!=""){$('#dropdownMenu1565').val(val.innerHTML);$('#dropdownMenu1565').html(val.innerHTML);}
     else{$('#dropdownMenu165').val('');$('#dropdownMenu165').html('Select Client');}
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
    
    <div class="dropdown"><button class="btn btn-warning dropdown-toggle" type="button" id="dropdownMenu1565"
            data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        Select Client
        <span class="caret"></span>
      </button>
      <ul class="dropdown-menu" name="xx-selectClient" aria-labelledby="dropdownMenu1565">
        <li><a id="yy-lloydBrayton" onclick="dropdownMenu1565Set(this);">Lloyd - 1 _ $ Brayton</a></li>
        <li><a id="yy-muiThreet" onclick="dropdownMenu1565Set(this);">Mui Threet</a></li>
        <li><a id="yy-wilsonBritton" onclick="dropdownMenu1565Set(this);">Wilson Britton</a></li>
        <li><a id="yy-gilbertMinto" onclick="dropdownMenu1565Set(this);">Gilbert Minto</a></li>
        <li><a id="yy-thomasinaLaney" onclick="dropdownMenu1565Set(this);">Thomasina Laney</a></li>
      </ul>
    </div>
    Adarsh Mohan
    • 1,283
    • 1
    • 9
    • 13
    • Adarsh thanks but all working fine now - where were you yesterday when I needed you LOL. But hopefully others will find this question useful and your answer looks quite elegant (though it has me confused). Thanks - Now if you would just like to sort out my next mess: http://stackoverflow.com/questions/33752771/cannot-get-jquery-call-right-for-eternicode-bootstap-datepicker I would forever be in your debt. – BeNice Nov 17 '15 at 09:02
    • Why dont you mark this an answer (If it works..) LOL.:D – Adarsh Mohan Nov 17 '15 at 09:26
    • Ardash thanks saw the page missed the specific bit "Names can contain letters, digits, underscores, and dollar signs." as I was so tired. So now I know - no dashes ... which is slightly annoying. – BeNice Nov 18 '15 at 04:47
    • It looks like the code is still working with all these conditions – Adarsh Mohan Nov 18 '15 at 05:10
    • Ardash sorry do not understand your code and you did supply it AFTER the answer had been provided. Not sure of the etiquette for that. But it was not an "answer" for me. Will take advice. – BeNice Nov 18 '15 at 18:48
    • Adash finally got this working. Completely NOT what I was looking for (passing a form variable through from a dropdown) BUT added to the solution above make a really excellent little tool. Will add a jsfiddle in a day or two. BRILLIANT! Thanks – BeNice Nov 18 '15 at 23:00
    • Adarsh (sorry for calling you Ardash!) your code is very useful (not what I was asking for but 100% useful). Question: Is there an easy way for the value to be passed back and displayed on using the browser's back button. At present doing form validation after submit I know tidy will come later) and everything comes back fine but obviously not the jQuery driven button. If this is easy great - if not pls do not bother as this will all get done "properly" when the code goes live. Once again thanks for a great addition to this solution – BeNice Nov 29 '15 at 22:32
    • 1
      Just wanted to say thanks again. Moving toward "production" and this code of yours has no doubt saved me 4-10 hours. Mahalo nui loa as we say over here – BeNice Jan 10 '16 at 04:09
    • @BeNice hi! You should consider mark this question as the correct one. – Leandro Bardelli Oct 15 '20 at 15:06