mcan
mcan

Reputation: 2082

Sending a Checkbox to Specific URL

For example; if a user clicks pop and rock boxes i want to send the page to www.mysite.com/?view=listen&tag[]=pop&tag[]=rock
If i use form code below it works on Firefox and IE fine. But if user clicks with Google Chrome, page goes to http://www.mysite.com/www.mysite.com/?view=listen&tag[0]pop&tag[1]rock& equal signs in front of tag names disappear. How can i get worked on google Chrome too?

<form action="http://www.mysite.com/">
    <input type="hidden" name="view" value="listen" />
    <input type="checkbox" name="tag[]" value="pop" />pop<br /><br />
    <input type="checkbox" name="tag[]" value="rock" />rock<br /><br />
    <input type="checkbox" name="tag[]" value="indie" />indie<br /><br />
    <input type="checkbox" name="tag[]" value="electronic" />electronic<br />
    <button type="submit">submit</button>
</form>

Upvotes: 0

Views: 162

Answers (1)

Viral Patel
Viral Patel

Reputation: 8601

I tried this. In google chrome, it does post the form to correct url with square brackets and equal sign:

Here is your code:

Form URL: http://jsbin.com/ihagon/1

When I select pop and rock and press submit, it goes to this url:

Target URL: http://jsbin.com/ihagon/1?view=listen&tag%5B%5D=pop&tag%5B%5D=rock

Here's the HTML code:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
</head>
<body>
  <form action="http://jsbin.com/ihagon/1">
    <input type="hidden" name="view" value="listen" />
    <input type="checkbox" name="tag[]" value="pop" />pop<br /><br />
    <input type="checkbox" name="tag[]" value="rock" />rock<br /><br />
    <input type="checkbox" name="tag[]" value="indie" />indie<br /><br />
    <input type="checkbox" name="tag[]" value="electronic" />electronic<br />
    <button type="submit">submit</button>
</form>
</body>
</html>

Let me know if I am missing something.

Upvotes: 1

Related Questions