Reputation:
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?
Upvotes: 0
Views: 49
Reputation:
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.
Upvotes: 2
Reputation: 1601
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>
Upvotes: 1
Reputation: 648
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.
Upvotes: 1