Reputation: 23
So I want two input boxes or prompts that have you enter your gamertag, and then another gamertag. the base url would be this: "http://joeydood.com/default.aspx?p1=&p2="
and then when someone enters: "gamertag1" then "gamertag2" and clicks the button, the link changes to: http://joeydood.com/default.aspx?p1=gamertag1&p2=gamertag2" and opens that link automatically
I was trying this
$(function () {
$('#submit').click(function() {
var url = "http://joeydood.com/default.aspx?p1=q";
url += $('#q').val();
window.location = url;
});
});
<input type="text" id="q" />
<input type="button" id="submit" value="submit" />
But it is not working , Please help.
Upvotes: 0
Views: 27
Reputation: 1864
You just had an extra "q" character in the URL. To make it a little easier to read, I'd recommend putting the p1
and p2
on the same line on which you're adding the gamertag to the URL.
You may also want to read more about query strings, so in the future you can better understand the structure of them.
$(function () {
$('#submit').click(function() {
var url = "http://joeydood.com/default.aspx";
url += '?p1=' + $('#q1').val();
url += '&p2=' + $('#q2').val();
window.location = url;
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
gamertag 1:
<input type="text" id="q1" />
gamertag 2:
<input type="text" id="q2" />
<input type="button" id="submit" value="submit" />
Upvotes: 1