I am stuck. My company is redesigning its website, but I am stuck with trying to jerry-rig a fix for a problem in the old site. I need to use JavaScript or jQuery.
When a form is submitted, a POST key is sent to the server that starts with "selectedItem_" followed by the item ID. The value attached to it is the text from the button, "Buy This". The complete key:value pair looks something like this:
selectedItem_IDME1KEXN_0_0 : "Buy This"
Because the form has several different versions of the same item, whoever programmed this put several buttons on the form, each with this kind of key. So there may be up to 4 or 5 buttons that are nearly identical. The values assigned to the them are the actualy price, like this:
selectedItem_IDME1KEXN_0_0 : 93.95
selectedItem_IDME2KEXN_0_0 : 99.95
selectedItem_IDME3KEXN_0_0 : 114.95
selectedItem_IDME4KEXN_0_0 : 119.95
All of these are getting sent to the server, which is causing the server to sometimes choose the wrong value. (And I have no idea why it was programmed like this, I am just trying to deal with it!)
MY QUESTION:
How can I use JavaScript or jQuery to evaluate what is currently stored in the POST before it is sent to the server? I would love to iterate through the keys that start with "selectedItem_" and pull out any bad ones before it is sent on its way.
submitevent, intercept the form data being submitted, and even potentially cancel / prevent the form from being submitted. By the way, a good question on StackOverflow shows what you have tried (it's called a Minimal, Complete, and Verifiable Example)