4

In my Laravel app, I have a form to select multiple options. However, I don't want to select multiple options by pressing CTRL and then selecting them. I just want to be able simply click on the options and they should be selected. And, if I click on a selected option again, then it should be de-selected.

How can I achieve this task? Here is an example of my select options list.

 <div class="form-group row">
  <label class="col-form-label" for="selectednames[]">Select Name</label>
 </div>
<div class="form-group row">                      
<select multiple name="selectednames[]">
  <option value="1">John</option>
  <option value="2">Sam</option>
  <option value="3">Max</option>
  <option value="4">Shawn</option>
</select>                      

P.S: I am using bootstrap and jquery in my application.

1

2 Answers 2

4

I think you want somethings like this :

$('select[multiple]').multiselect()
<!DOCTYPE html>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css" />

</head>
<body>

<select multiple="multiple">
    <option value="cheese">Cheese</option>
    <option value="tomatoes">Tomatoes</option>
    <option value="mozarella">Mozzarella</option>
    <option value="mushrooms">Mushrooms</option>
    <option value="pepperoni">Pepperoni</option>
    <option value="onions">Onions</option>
</select>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.min.js"></script>
</body>
</html>

Sign up to request clarification or add additional context in comments.

Comments

2

simply use checkbox type as input instead of option, like that:

<div class="form-check">
    <input type="checkbox" name="selectednames[]" value = "1" />
    <input type="checkbox" name="selectednames[]" value = "2" />
    <input type="checkbox" name="selectednames[]" value = "3" />
    <input type="checkbox" name="selectednames[]" value = "4" />
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.