Get value from input in modal

Hi, I have a mod in bootstrap and inside I have an input field.

<input type="text" name="quota" class="form-control" id="quotas" value="'.$storagequota.'" maxlength="20" > 

I also have a button that, when pressed, calls a function, so I can get the value of the input field

 function getQuota(){ quota = $("#quotas").val(); alert(quota); } 

The problem is that I cannot get the value entered by the user. The strange thing is that I have another modal on another page that works the same way. Can anyone help with this? thanks in advance

+6
source share
2 answers

Just put the modality id in front of the login id

 $("#registration_modal #useremail").val().trim() 
+7
source

Your code is correct.

Just write the JS function tag in the head tag.

Here is your code

 <html> <head> <script> function testFun() { quota = $("#quotas").val(); alert(quota); } </script> </head> <body> <div id="admin" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content animated bounceInDown"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Settings</h4> </div> <div class="modal-body"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab1" data-toggle="tab">Quota</a> </li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab1"> </br> <div id="table" class="col-lg-12"></div> <label for="Quota">Quota</label> <div class="input-group form-group"> <input type="text" name="quota" class="form-control" id="quotas" value="10" maxlength="20"> <div class="input-group-addon input-group-btn-custom "> <span id="type">Gb</span> </div> </div> </div> </br> </br> <button type="submit" class="btn btn-primary" onclick="testFun()" id="admin">Submit</button> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> </div> </div> </div> </div> </body> </html> 

Working demo

0
source

All Articles