Help w/ Drop-Down Menu (Select / Option)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help w/ Drop-Down Menu (Select / Option)

Post by Celauran »

The functions are separate. The trouble is they're targeting an ID, which is meant to be unique but isn't. You're creating multiple forms inside a loop and giving them all the same ID. Rather than selecting the ID within the function, try using the calling item instead.
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Help w/ Drop-Down Menu (Select / Option)

Post by diseman »

ok, so I removed the onChange event and put a submit button instead and it works. So, as you suggested, the problem is related to the javascript code. I'm sorry, but what do you mean by "try using the calling item instead?" I googled "calling item" and think you're meaning something with the "#assign_contractor." Could you show me what you mean?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help w/ Drop-Down Menu (Select / Option)

Post by Celauran »

Remove the ID since it's not going to be unique. Use a class instead and set a listener on that class' change event.

Something like this

Code: Select all

$(function() {
    $('.assign_contractor').change(function() {
        $(this).submit();
    });
})();
User avatar
diseman
Forum Contributor
Posts: 174
Joined: Mon Jul 26, 2010 1:30 pm
Location: Florida

Re: Help w/ Drop-Down Menu (Select / Option)

Post by diseman »

So there's something to be said for walking away from something for a little time and coming back to it.

I found, what I guess was a mistake in your function, and changed it to look more like the current functions I have. Then it occurred to me the class you were referring to could be put in the <form>, which I didn't know you could do.

Now it all seems to be working as hoped.

Long and hard lessons, but good ones for my growing toolbox.

Also didn't know you could:

Code: Select all

$contractor = mysqli_real_escape_string($con, $_POST['assign_contractor']);
specifically, the ['assign_contractor'] part.

Funny how CLOSE I've come, over the 100 iterations I've tried, to something very similar to what I have now; excluding the javascript piece of course. It was the one hidden element in the form that was the biggest oversight.

Ok, so thank you again very much. Couldn't have gotten here without your help.
Post Reply