Reputation: 3
I am new to HTML. I need code that generates and redirects to a URL depending on the value of form input elements. For example, with two fields name
and roll
, once populated it should generate http://example.com/name/roll
and send the user to the URL.
Is this possible? I was able to create the URL http://webaddress/data+data+data
but not with /
. Please guys; if you may help, it would be very much appreciated. Thanks in advance.
Upvotes: 0
Views: 438
Reputation: 2893
On front-end, this will be best done with JavaScript, simply fetch the values in the form and insert it in the URL as you desire.
Sample HTML
<form onsubmit="myFunction();return false">
<input name="name" id="name">
<input name="roll" id="roll">
</form>
Sample JavaScript
<script>
function myFunction(){
//Get values
var name = document.getElementById('name').value;
var roll = document.getElementById('roll').value;
//Redirect
window.location = "http://webaddress/"+name+"/"+roll;
}
</script>
Upvotes: 0
Reputation: 356
Try this One
var roll=document.getElementById("rollhtml");
var x = document.getElementById("namehtml");
var url="Your URL here"+roll+x;
<input type="text" id="rollhtml" placeholder="Roll" value="">
<input type="text" id="namehtml" placeholder="Name">
Upvotes: 0
Reputation: 2256
var name = "Jone"
var roll = 100;
var url = "http://webaddgess/"+name+"/"+roll;
Upvotes: 1