0

I'm trying to create a form where a user enters a username, and then clicks a button. Then it opens a window with the parameters in the url like so below.

<script type="javascript">
function open(id) {
    window.open("http://linkhere.com/~Robby/lcpVote.php?u="+ document.getElementById(id).innerHTML +"&s=" + id + "&a=addVote");
}
</script>
<input type="text" placeholder="MC Username" id="name" style="width:100%">

And when they click on the button below,

<button class="btn btn-primary" style="width:100%" onclick="open('1')" id="1" href="#">MCServers.org</button>

It opens the following url

http://LINKHERE.COM/~Robby/lcpVote.php?u=USERNAMEFROMFORM&s=IDFROMBUTTON&a=addVote

But when I click it using my code it just returns a white page?

6
  • Is that HTML5? Otherwise numeric id is not allowed. Also, you're not properly escaping your query string parameters. Commented Dec 30, 2012 at 5:45
  • What do you mean by that? I'm absolutely TERRIBLE with javascript. Commented Dec 30, 2012 at 5:46
  • Why don't you just use a form using the get method? Commented Dec 30, 2012 at 5:46
  • I'm really stupid, thanks! Commented Dec 30, 2012 at 5:47
  • Also please...for the future of htmls purpose, please end your input tag as /> rather than just > hahaha Commented Dec 30, 2012 at 5:49

3 Answers 3

2

Use method="get" on the form. This will make the query string suitable to what you want depending on the input names within your form.

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

Comments

1

it is because you are passing in 1 as an id in your onclick function. You should instead pass in the id of the input field. So it should be:

<button class="btn btn-primary" style="width:100%" onclick="open('name')" id="1" href="#">MCServers.org</button>

Where name is your input fields id.

Comments

1

Replace innerHTML by value..

window.open("http://linkhere.com/~Robby/lcpVote.php?u="+ document.getElementById(id).value+"&s=" + id + "&a=addVote");

and replace 1 by name..

<button class="btn btn-primary" style="width:100%" onclick="open('name')" id="1" href="#">MCServers.org</button>

Comments

Your Answer

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