I currently have the basic form page set up listed below. How can I use AJAX instead to redirect to a new page. What I want to do is have a pre-set username as option one that directs to Page A with the relevant information. However, if a user decides to add in a new username, I want it to make a AJAX call to return a relevant JSON object with their information and load Page A with their information.
<form action="/login" id="loginForm" method="post" required>
<p>Select the test user or add a new one:
<select id="selectUser" name="username" required>
<option value = "">-- Select an Option --</option>
<option value = "#>1</option>
<option value = "2">Add new</option>
</select>
</p>
<div class="newUser">
<p>Please Specify:
<label id="userNameLabel">
<input name="New Username" type="text" placeholder="New Username" size="30" required/>
</label>
</p>
</div>
<div id="submitHolder">
<input type="button" value="Submit" id="submitButton">
<input type="hidden" id="hiddenInput">
</div>
With the following Javascript:
$(document).ready(function(){
$("p select[name=username]").change(function(e){
if ($("p select[name=username]").val() == "2"){
$(".newAccountInfo").show();
} else{
$(".newAccountInfo").hide();
}
});
$(function(){
$('#selectUser').on('change', function () {
var url = $(this).val();
$("#submitButton").on("click", function(){
window.location = url;
});
});
});
I'm still really new to AJAX, so I'm not sure how I would go about doing this type of fake "login".
