how to retrieve input from a certain html id

how to get value of textbox in javascript from html
html input
get input value jquery
html <input value
get input value javascript
html form
how to get value of textbox in javascript function
javascript input box

I have this html

 <div class="table-responsive table-responsive-data2">
<table class="table table-data2" id="resulttable" style="display: block;">
    <thead>
        <tr>

            <th>NSN</th>
            <th>Name</th>
            <th>QTY</th>
            <th>Price ($)</th>
            <th>Manufacturer</th>
            <th>Part Number</th>
            <th>Shipping</th>
        </tr>
    </thead>
    <tbody id="producttable">



        <!--  -->


        <form id="myform0"></form>

        <tr class="tr-shadow">

            <td style="width: 90px;">
                <div>123
                </div>
                <div>
                    <br>
                    <button type="button" class="btn btn-secondary mb-1 btn-sm" data-toggle="modal" data-target="#productModal" onclick="showproductmodal(123)">
                        Add Photos
                    </button>
                </div>

            </td>
            <td>

                <span class="status--process">
                    <input class="au-input au-input--sm" id="Nomenclature" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
                </span>

            </td>
            <td class="desc">

                <input class="au-input au-input--sm " id="Qty" type="text" name="search" placeholder="i.e. 20 EA" style="width: 100px;">


            </td>
            <td class="desc">

                <input class="au-input au-input--sm" id="Price" type="text" name="search" placeholder="i.e 900" style="width: 90px;">

            </td>

            <td>
                <span class="status--process">
                    <input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
                </span>

            </td>
            <td class="desc">
                <input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
            </td>

            <td class="status--process">

                <input class="au-input au-input--sm" type="text" name="search" placeholder="shipping cost" style="width: 120px; height: 30px;"><br>

                <select name="selectSm" id="SelectLm" class="form-control-sm form-control" style="width: 120px;">


                    <option value="0">Please select</option>
                    <option value="1">Option #1</option>
                    <option value="2">Option #2</option>
                    <option value="3">Option #3</option>
                    <option value="4">Option #4</option>
                    <option value="5">Option #5</option>
                </select>
            </td>
            <td>

                <button type="button" class="btn btn-primary btn-md" onclick="postitem(0)">Submit</button>

            </td>
        </tr>


        <tr class="spacer"></tr>


        <form id="myform1"></form>

        <tr class="tr-shadow">

            <td style="width: 90px;">
                <div>343
                </div>
                <div>
                    <br>
                    <button type="button" class="btn btn-secondary mb-1 btn-sm" data-toggle="modal" data-target="#productModal" onclick="showproductmodal(343)">
                        Add Photos
                    </button>
                </div>

            </td>
            <td>

                <span class="status--process">
                    <input class="au-input au-input--sm" id="Nomenclature" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
                </span>

            </td>
            <td class="desc">

                <input class="au-input au-input--sm " id="Qty" type="text" name="search" placeholder="i.e. 20 EA" style="width: 100px;">


            </td>
            <td class="desc">

                <input class="au-input au-input--sm" id="Price" type="text" name="search" placeholder="i.e 900" style="width: 90px;">

            </td>

            <td>
                <span class="status--process">
                    <input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
                </span>

            </td>
            <td class="desc">
                <input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
            </td>

            <td class="status--process">

                <input class="au-input au-input--sm" type="text" name="search" placeholder="shipping cost" style="width: 120px; height: 30px;"><br>

                <select name="selectSm" id="SelectLm" class="form-control-sm form-control" style="width: 120px;">


                    <option value="0">Please select</option>
                    <option value="1">Option #1</option>
                    <option value="2">Option #2</option>
                    <option value="3">Option #3</option>
                    <option value="4">Option #4</option>
                    <option value="5">Option #5</option>
                </select>
            </td>
            <td>

                <button type="button" class="btn btn-primary btn-md" onclick="postitem(1)">Submit</button>

            </td>
        </tr>


        <tr class="spacer"></tr>


        <form id="myform2"></form>

        <tr class="tr-shadow">

            <td style="width: 90px;">
                <div>212
                </div>
                <div>
                    <br>
                    <button type="button" class="btn btn-secondary mb-1 btn-sm" data-toggle="modal" data-target="#productModal" onclick="showproductmodal(212)">
                        Add Photos
                    </button>
                </div>

            </td>
            <td>

                <span class="status--process">
                    <input class="au-input au-input--sm" id="Nomenclature" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
                </span>

            </td>
            <td class="desc">

                <input class="au-input au-input--sm " id="Qty" type="text" name="search" placeholder="i.e. 20 EA" style="width: 100px;">


            </td>
            <td class="desc">

                <input class="au-input au-input--sm" id="Price" type="text" name="search" placeholder="i.e 900" style="width: 90px;">

            </td>

            <td>
                <span class="status--process">
                    <input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
                </span>

            </td>
            <td class="desc">
                <input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas &amp; reports..." style="width: 90px;">
            </td>

            <td class="status--process">

                <input class="au-input au-input--sm" type="text" name="search" placeholder="shipping cost" style="width: 120px; height: 30px;"><br>

                <select name="selectSm" id="SelectLm" class="form-control-sm form-control" style="width: 120px;">


                    <option value="0">Please select</option>
                    <option value="1">Option #1</option>
                    <option value="2">Option #2</option>
                    <option value="3">Option #3</option>
                    <option value="4">Option #4</option>
                    <option value="5">Option #5</option>
                </select>
            </td>
            <td>

                <button type="button" class="btn btn-primary btn-md" onclick="postitem(2)">Submit</button>

            </td>
        </tr>


        <tr class="spacer"></tr>

    </tbody>

</table>

and I have a function that is triggered from the dynamically created created html

function postitem(index) {
   var formid='#myform'+index

    $('input').each(function(index){

     console.log($(this).val()); 
 });
}

the selector $('input') captures all the input value in the html, what I really want is for it to capture only the input within a given #id. So I tried

 $('#myform1 input').each(function(index){

     console.log($(this).val()); 
 });

and

$(formid).('input')

and none of them yielded any result. How can implement retrieving a input within a div id?


You can access the input very much directly without using the parent $("#idInput") or for accessing it through parent you can use $('#myform1 #idInput'). But make sure you have defined the ids of the element at the time of generation.

There is another way of doing it you can use it as array $('#myform1 input')[index]. Note the index should be the desired number of appearance your input.

HTML input form Attribute, <input> form Attribute. ❮ HTML <input> tag. Example. An input field located outside the HTML form (but still a part of the form): <input type="text" id="lname" name="lname" form="form1">. Try it Yourself » XML Certificate · Get Certified »​  Using The id Attribute. The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). The id value can be used by CSS and JavaScript to perform certain tasks for the element with the specific id value. In CSS, to select an element with a specific id, write a hash (#) character, followed by the id of the element:


try this:


    $("input").parent( "#myform1" );

HTML DOM Input Text value Property, Input Text value Property. ❮ Input Text Object Value, Description. text, Specifies the value of the input text field Example. Get the value of a text field:. To select specific elements, you can either right-click them in the preview pane, or left-click the code in the left-hand inspector window. The CSS styles for each element are shown on the right side, with the most dominant selector (the .class-name or #id-name) shown first.


As i said in my comment, your javascript codes are true. but there is two problem that cause you have not any result:

  1. #myform1 is blank.

  2. In another form you have some input controls, but they have not any value.

Below I added an input with some value to your form #myform1 and test your code:

$('#myform1 input').each(function(index){

     console.log($(this).val()); 
});
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<form id="myform1"><input value="Some Thing" /></form>

    

How to Get the Value of Text Input Field Using JavaScript, You can simply use the value property of the DOM input element to get the The following example will display the entered text in the input field on button DOCTYPE html> id="myInput"> Here are some more FAQ related to this topic​:. Refresh the index.html document in your browser, and click on the Test Button input; the get object by class is activated, and the result is shown in Figure C as displayed in Chrome 17.0.9: Figure C


<input type="search">, input elements of type search are text fields designed for the user to enter search You can retrieve this using the HTMLInputElement.value property in JavaScript​. The values of the list attribute is the id of a <datalist> element located in the If no maxlength is specified, or an invalid value is specified, the  Setting the input attribute to text allows means the input form field will be a text box. The only other attribute which each text box needs is the id attribute. In the cases of these 2 text boxes, the id attributes are firstname and lastname. This is a very important attribute because this is the attribute which Javascript will use in order to extract information each text box.


<input>: The Input (Form Input) element, The HTML input element is used to create interactive controls for web-based If this attribute is not specified, the default type adopted is text . reset, A button that resets the contents of the form to default values. This string's value, if present, must match the id of a <form> element in the same document. I know how to access an element by it´s id, but how could I get the id of an element Let´s say I have var id; function getid() { var get=get the id of the element that triggered the function; id


Searching: getElement*, querySelector*, If an element has the id attribute, we can get the element using the method document. Also, when one reads JS code and doesn't have HTML in view, it's not There can be only one element in the document with the given id . getElementsByTagName ( 'input' ) ; for ( let input of inputs ) { alert ( input  Retrieve the data. The retrieve function returns all of the data as an associative array. Call this function after setting up all required filtering and sorting parameters. Alternatively, if you'd just like to display a table without processing the data, call display_as_html_table (see below).