Get value from input in model
Asked Answered
L

3

11

I have a bootstrap model and inside I have an input field.

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

Also, I have a button which when clicked 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 that user typed. The weird thing is that i have another model in another page that works in the same way. Can someone help with that? Thanks in advance.

Laxation answered 28/8, 2015 at 16:1 Comment(3)
can you provide a fiddle ?Egret
jsfiddle.net/6n9jd1nk/2Laxation
is there multiple elements with same ID quotas in your page?Zipper
F
12

Just put the id of the modal before the id of the input

$("#registration_modal #useremail").val().trim()
Farika answered 31/5, 2016 at 22:12 Comment(1)
This should be the top answer. It worked just as I suspected. Thank you!Fabria
E
0

Your code is correct .

Just write the JS function in 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

Egret answered 28/8, 2015 at 16:14 Comment(4)
the problem is that i have a main file that i have all my function and a file that has my main page that i call it in every page. i put it in both but still the same. i cant figure out what else i would doLaxation
then just load that file in head section .Egret
i load it in the head sectionLaxation
then open browser console and try again , you will get an error paste it here. some one may help you.Egret
E
-1

It not work for me because I have a records table below modal. So when I try it's show me data table otherwise input value

Erinaceous answered 16/8, 2022 at 13:41 Comment(1)
Please provide more information so we can understand you better.Victory

© 2022 - 2024 — McMap. All rights reserved.