0

I want to create a object form of a file input in the form, How i can do it . How I can Create form object of file input

<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<form id="helooo">
  <input type="text" name="foo1" value="" />
  <input type="text" name="foo2" value="" id="r1"/>
<input type="file" name="f1" value="" id="r2"/>
<button type="submit" id="s1"> ab</button>
</form>




<script>
$(".quote_save").click(function() {
var oElements = {};
$('form'){
    oElements[this.name] =  = this.value;
});
});
</script>
</body>
</html>
sarath
  • 11
  • 1
  • 1
  • 4

2 Answers2

1

First you need to have the method and enctype(necessary for file input).

HTML:

<form id="helooo" method="post" enctype="multipart/form-data">
  <input type="text" name="foo1" value="" />
  <input type="text" name="foo2" value="" id="r1"/>
<input type="file" name="f1" value="" id="r2"/>
<button type="submit" id="s1" class='quote_save'> ab</button>
</form>

Javascript:

<script>
 $(function(){
 $(".quote_save").submit(function() {
  var form_data=$('#helooo').serialize();//string format
  var form_data=$('#helooo').serializeArray();//Arrayformat
});
});
</script>

Reference:-/ serialize

lalithkumar
  • 3,480
  • 4
  • 24
  • 40
0

Try the below code

<script>
 $(".quote_save").click(function() {

  var formData=$('#helooo').serialize();
});
</script>
Sagar V
  • 12,158
  • 7
  • 41
  • 68
Sagar Roy
  • 433
  • 4
  • 12