1

My Code is

    $("#section-form").submit(function (e) {
        e.preventDefault();
        var get_data = JSON.stringify($('#common-element-form').serializeArray());
        console.log(get_data);
        var common_element_data = JSON.parse(get_data);
        $(common_element_data).each(function (idx, val) {
            console.log(common_element_data);
        });

    });
<form id="common-element-form">

                <div class="form-group input select" id="campus-select-parent-div">
                    <label for="campus-type" class="col-sm-3 control-label text-right">Campus Type</label>

                    <div id="container-campus-select" class="col-sm-9">

                    <select class="form-control" name="campus-select" id="campus-select"><option value="">Select</option><option value="1">Collectorate Balika Biddya Niketan</option><option value="27">qwe</option></select></div>
                </div><br><br><br>

                <div class="form-group input select">
                    <label for="shift-select" class="col-sm-3 control-label text-right">Shift Type</label>

                    <div id="container-shift-select" class="col-sm-9 ">

                        <select name="shift-select" id="shift-select" class="form-control">
                        <option value="">Select</option><option value="10">Day</option><option value="29">Night</option></select>
                    </div>
                </div><br><br>
                <div class="form-group input select">
                    <label for="medium-select" class="col-sm-3 control-label text-right">Medium Type</label>

                    <div id="container-medium-select" class="col-sm-9 "><input class="form-control" id="medium-select" type="text" medium-element-id="16" value="700"></div>
                </div>
            </form>

But it's showing

Uncaught Error: Syntax error, unrecognized expression: campus-select=1&shift-select=10

That means it can't parse the input

<input class="form-control" id="medium-select" type="text" medium-element-id="16" value="700">

any suggestion ??

1 Answer 1

1

Try this

   $(document).ready(function() { 
      $("#section-form").submit(function(e) {
         var get_data = $("#common-element-form").serializeArray();
         $.each(get_data, function (index, elem) {
           alert("name: " + elem.name)
           alert("value: " + elem.value)
           alert($('[name='+ elem.name +']').data("medium-element-id"))
         });
         e.preventDefault();
      });
   });

You can't able to get the user defined attribute value from SerializeArray().Instead try some alternatives like

var data_arr=$('input').map(function(){ return $(this).data('medium-element-id');}).get(); 
console.log(data_arr); 

And also change your medium-element-id attribute as data attribute

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

5 Comments

your medium-select input field doesn't have the name attribute. that is the actual problem
i've fixed that. But now problem is SerializeArray() can't parse user defined attributes . @Preethi Mano
I need the value of medium-element-id attribute .But SerializeArray() is not producing it :( @Preethi Mano
You can't able to achieve that through SerializeArray().Instead try some alternatives like var data_arr=$('input').map(function(){ return $(this).data('medium-element-id');}).get(); console.log(data_arr); But it should be the data attribute
it's working .can you post this as answer ? I can accept this

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.