skip to Main Content

Hi guys i am trying to get the image value from my input using jquery but it is showing value as undefined

Here is my input

<input placeholder="image" class="width-dynamic proba dva" type="file" onchange="updateQuesMark(2,0,this.value,2,1,0)" name="q2[]">

Here is in my ajax i tried like this

var totalfiles = $("input[name='q2']").val();

When i tired like this i am getting value as undefined..
Can anyone help me where i did mistake..Tq in advance.

2

Answers


  1. You need to set the parameter as "input[name='q2[]']"

    var totalfiles = $("input[name='q2[]']").val();
    
    console.log(totalfiles);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input placeholder="image" class="width-dynamic proba dva" type="file" onchange="updateQuesMark(2,0,this.value,2,1,0)" name="q2[]">
    Login or Signup to reply.
  2. change as $("input[name='q2[]']")

    function updateQuesMark(){
      var totalfiles = $("input[name='q2[]']").val();
      console.log(totalfiles);
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input placeholder="image" class="width-dynamic proba dva" type="file" onchange="updateQuesMark(2,0,this.value,2,1,0)" name="q2[]">
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search