Skip to content

Instantly share code, notes, and snippets.

@erhanyasar
Last active Jun 9, 2020
Embed
What would you like to do?
Form Control
$(document).ready(function() {
let f1err = 0,
f2err = 0,
f3err = 0,
date = new Date();
$("#sendBTN").click(function() {
if (($("#username").val() == "") || ($("#phone").val() == "")) {
f1err = 1;
if ($("#username").val() == "") {
$(".username").addClass("has-error");
$(".namesurname_txt").css("display","block");
} else {
$(".phone").addClass("has-error");
$(".phone_txt").css("display","block");
}
} else {
f1err = 0;
if ($("#username").val() != "") {
$(".username").removeClass("has-error");
$(".namesurname_txt").css("display","none");
} else {
$(".phone").removeClass("has-error");
$(".phone_txt").css("display","none");
}
}
if (($("#byear").val() == "") || ((date.getFullYear() - $("#byear").val()) < 18)) {
f3err = 1;
$(".byear").addClass("has-error");
$(".byear_txt").css("display","block");
} else {
f3err = 0;
$(".byear").removeClass("has-error");
$(".byear_txt").css("display","none");
}
if (f1err == 0 && f2err == 0 && f3err == 0) {
window.location = "confirmation.html?username=" + $("#username").val() + "&phone=" + $("#phone").val();
return true;
} else
return false;
});
if ($("#username").exists()) {
var usernametxt = $.urlParam('username').replace("%20", " ");
$("#username").html(usernametxt);
}
if ($("#phone").exists()) {
var phonetxt = $.urlParam2('phone').replace("%20", " ");
$("#phone").html(phonetxt);
}
});
$.urlParam = function(name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
$.urlParam2 = function(name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
jQuery.fn.exists = function() {
return this.length > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment