Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my ajaxForm call send all forms on the page, rather than just the one I want?

Tags:

jquery

forms

Good day.

When I use the following code, it sends all forms on the page, instead of just the one form I specified.

$('.imagetemp').on('change',function(){

var id = this.id;
var arr = id.split('upload');
var count = arr[1];

var form = '#imagetempform' + count;

$("form").ajaxForm(
...
...
...

Tell me please how to send just one form?

like image 216
Alex N Avatar asked Nov 24 '25 01:11

Alex N


1 Answers

As form is a variable, you need to change:

$("form")

To:

$(form)

Otherwise you're referencing all form elements on the page as a variable wrapped in quotes is no longer a variable - it's a string, which $() interprets as a jQuery selector.

Refer to jQuery's Element Selector ("element") documentation for more info.


Edit: (from edited question):

P.S.: $(form).ajax() not work test this you can see here http://testwork.ru/10006/template1.php (before image click on button 'выбрать')...

This is because your forms have no IDs.

<form name="imagetempform1" class="..." ... >...</form>

# is used to select IDs. You can either add the IDs in:

<form name="imagetempform1" id="imagetempform1" class="..." ... >...</form>

Or you can change your selector to select the name instead with:

var form = "[name='imagetempform" + count + "']";
like image 193
James Donnelly Avatar answered Nov 26 '25 16:11

James Donnelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!