2

I have a page with a check box so that when its checked, it will submit values and parameters via GET, this is how it looks like by default:

Passing two product SKUs:

http://example.com/product-comparisons/?product-skus=1&product-skus=2

Passing only one product SKUs:

http://example.com/product-comparisons/?product-skus=1

OR this:

http://example.com/product-comparisons/?product-skus=2

What I want to accomplish is to change the GET parameter ONLY when passing two or more products such as this:

http://example.com/product-comparisons/?product-skus=1&product-skus=2

INTO THIS:

http://example.com/product-comparisons/?product-skus=1,2

And when there are no checked products but the form is submitted, it will change the URL from:

http://example.com/product-comparisons/

INTO THIS:

http://example.com/product-comparisons/?product-skus=0

that is adding 0 to the product-skus query string variable.

I already have a jQuery code that will run when the submit button is clicked:

jQuery( document ).ready( function( $ ) {
$('#myform').submit( function() {

    //change the GET URL parameters


 });

});

But I'm stuck with the rest of the process. I would like this to happen when submitting the form. I would be glad if someone can provide some sample code to get started. Thank you so much.

1 Answer 1

1

I'm going to offer a suggestion that doesn't directly answer your question, but which will probably solve your problem, and may save you a lot of work and headache in the process.

I assume you want to modify the GET params because your server-side application is only receiving one of the values when many are passed, and you want to split the comma-delimited param to solve your problem.

There's an easier alternative.

Change your checkbox name attribute to product_skus[], and when you read it on your server-side app, it will be retrieved as an array.

e.g.:

http://example.com/product-comparisons/?product-skus[]=1&product-skus[]=2

If you're reading this in PHP:

print_r($_GET['product_skus']);`

Will give you:

Array(0 => '1', 1 => '2')

Hope that helps you out!

(PS - You can do this with other server-side languages, too, like Python, and I'm sure most other modern languages. Java and .NET can do it without the [] syntax, so I'm pretty sure you're not using those.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.