N. Didier N. Didier -4 years ago 131
PHP Question

JS function triggered by half-random id

I have many forms

<form action="#" method="post" id="my_id"> ... </form>

I have 1 form per element in my DB and i also have a JS function who send a SQL request based on the form i submit

$("#my_id").submit(function() { ... }

It does work for my 1st form only so i tried to change the id for each form like this

<form action="#" method="post" id="my_id<?php echo nb ?>"> ... </form>

is an auto-incremented number. But the problem it doesn't enter in my function anymore (
for nb = 1, my_id != my_id1

How can i change my condition in the JS part? add wildcard?

$("#my_id*").submit(function() { ... }

Answer Source

I think this is what you are after:


This will select all form elements with ID starting with "my_id" .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download