HOW TO GET ELEMENT NAME OF VALUE?

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 914  View(s)
Ratings:
Rate this:
need to get all text of value, then use json to send the value to insert all of price to the database, but i had the problem, i can't get the text of all value where input text name='price'. here this is HTML code:
here is Html code:

<input type='text' id='price1' name='price[]'/>

 

<input type='text' id='price2' name='price[]'/>

 

<button type='button' id='btn'/>

JQuery code:

 

<script>

    $('#btn').click(function (e) {

        var myprice = [];

        myprice = $("*[name='price']").val();

        $.post(

            "index.php",

            {

                type: "insert",

                price: myprice,

            }

        ).done(function (data) {

            console.log(data);

        })

    });

</script>


  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to get element name of value?

    you can use .map() to get all values

    <script>

        var myprice = $.map($('[name="price[]"]'), function (v, i) {

            return v.value;

        }).join(',');

    </script>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!