mardi 5 avril 2016

Looking for particular JS method to confirm radio button selection

Love this place, learnt mountains of PHP here, and some JS.

I am fairly young in my JS experience, and have a question about how to solve this issue I am having using client side JS validation.

Basically, this is an online ordering system I built, and have just finished implementing the ability for the admins/managers to split & part ship an order. When that action is selected, I have some JS that shows a pair of radio buttons next to each line item in the order with the option to "do nothing" or "split this item to backorder", which then creates a second order in the system, moves any selected items to it and marks it for backorder.

This all works perfectly, but the issue is when the admin/manager chooses to "split & backorder" but either: A) chooses no items to split B) Chooses all of the items on an order to split C) Tries to split & backorder and order with only 1 line item (for validation purposes, this is the same as selecting all items)

Resulting in either the original or split order potentially having no items attached to it.

I want to perform a JS validation that basically stops the PHP post and displays an alert if either condition of no items or all items being selected to split & backorder.

I have looked at doing this with a JS .onclick function and using a loop with a variable to count up total items & items selected and compare, but the issue is making this dynamic enough on to work with each order as the form radio buttons names change with each order (done by PHP). In PHP I would just have expanded the array with a loop from the post but I dont even know where to begin with that in client side JS.

Sorry for the long winded and confusing question!

Any pointers much appreciated.




Aucun commentaire:

Enregistrer un commentaire