0

I have 5 checkboxes, each has its own value.

If I submit them normally, I get a $_GET request like

http://siteurl.com/?&checkbox1=a&checkbox2=b&checkbox3=c....

It looks ugly, so I was thinking I could send a hidden input instead, like:

http://site.url.com/?checkeddata=a,b,c...

So how could I pick-up data from the checkboxes and store it in the hidden field?

2 Answers 2

1

If you don't want user to see the data sumited, you should consider using the POST method.

See how to choose between get or post here

By the way, you should also consider using the .serialize() function from the jquery API.

See also this SO thread on POST and Serialize: jquery serialize and $.post

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

Comments

1

I would suggest just making your individual checkbox names presentable, there's nothing that "ugly" about that URL and it is more clear. If you don't want the user to see anything, consider POST.

If you really want to do it, you will want to:

  • catch the submit button click with jquery
  • Use Jquery to find the value of each of your checkboxes: $("#checkbox_id").is(':checked');
  • Build a new parameter with the values you checked
  • Keep the checkboxes from being submitted by either placing them outside the form in the DOM, removing on submit, or using serialize to create a new parameter list and submitting that.

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.