I am trying to show alert message when user failed to login with url value .
<script type="text/javascript">
<!--
var retVal = confirm("Login FAILED! Do you want to continue ?");
if( retVal == true ){
window.location.href = "login.php";
return true;
}else{
alert("User does not want to continue!");
return false;
}
//-->
</script>
this is url value
/?redirect_to=%2Fstarstruckmedia%2F%3Flogin%3Dfailed%26redirect_to%3D%252Fstarstruckmedia%252F&login=failed
You can't use return unless you are in a function. Take those lines out and your code works.
var retVal = confirm("Login FAILED! Do you want to continue ?");
if(retVal){
window.location.href = "login.php";
} else {
alert("User does not want to continue!\n" + window.location.href);
}
You can obtain the url of the current page using window.location.href. See this for details.
var retVal = confirm("Login FAILED! Do you want to continue ?");
if( retVal == true ){
window.location.href = "login.php";
}else{
alert(window.location.href);
}
Related
If my URL is any of these type:
domain.com/page.html?refer=whatsapp
domain.com/page.html#whatsapp
Then I want to show a dialogue that shows "You have been referred from Whatsapp".
And if the url is accessed without the whatsapp part, then it must not show the dialoge box.
What I have tried is:
<script type="text/javascript">
var url = window.location.href;
if (url.search("#wa") >= 0) {
//found it, now do something
}
alert("Good Afternoon");
} else {
null //if not just do nothing
}
</script>
But no luck.
It helps you
var url = window.location.href;
// For example. In real app remove it
url = 'http://website.com/page.html#whatsapp';
// Search our #ID
var source = url.substring(url.lastIndexOf('#') + 1);
// For salutation text
var salutation = null;
// Iterate variants
switch ( source ) {
case 'whatsapp' : salutation = 'You have been referred from Whatsapp'; break;
default : salutation = 'unknown website';
}
alert ( salutation );
I am working on a registration form with jquery ajax. My jQuery Code is as follow :
function validateData()
{
var email = jQuery("#email").val();
var username = jQuery("#username").val();
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
var regex = new RegExp(/^\+?[0-9(),.-]+$/);
if(!emailReg.test(email))
{
alert('Please enter valid email');
return false;
}
var agreement = jQuery("#agereement").is(":checked");
if(agreement == false)
{
alert("Please agree with the agreement !!! ");
return false;
}
var pass = jQuery("#password").val();
var repass = jQuery("#repeatpass").val();
if(pass != repass)
{
alert("Password & Repeat Password Should be same");
return false;
}
var FirstData = "email=" + email+"&username="+username;
var url = "ajaxcheck.php";
jQuery.ajax({
dataType : 'html',
type: 'GET',
url : url,
data : FirstData,
complete : function() { },
success: function(data)
{
if(data == '')
{
alert("No Problem");
var flag = "true";
}
else{
alert("Username Or Email ID Already Exists");
var flag = "false";
}
}
});
alert(flag);
return flag;
}
</script>
When I submit the form and enters the value of username which is already exists in DB then it alerts the Username Or Email ID Already Exists but submit the form instead of staying on the page. What Should I do if it error comes then it should stay on the page instead of submitting the form
When you write:
var flag = "true";
…
var flag = "false";
…
return flag;
The problem is that "true" and "false" are strings containing the word “true” or “false”. To get the actual boolean values true or false, get rid of the quotes:
var flag = true;
…
var flag = false;
…
return flag;
Event handlers only understand boolean return values, not strings.
Use onsubmit in form tag
<form onsubmit="return validateData();">
....
<input type="submit">
</form>
I'm trying to help you from another angle.
Here is an example on how to do form validation (with bootstrap/php/jquery): http://formvalidation.io/examples/contact-form/
Ajax ".done" happens when you get a successful response from the server and ".fail" happens when sending a request or receiving the response has failed. Assuming you want to check if email exists then you can use something in the lines of:
if(response.IsEmailValid === 'false')
{
$('#alertContainer')
.removeClass('alert-success')
.addClass('alert-warning')
.html('Sorry, email has been taken')
.show()
}
You're setting flag to strings, not boolean values. Try using true and false instead of "true" and "false", both of which are truthy.
assume that login.check() checks for validation of the fields after that I post the data to 'check.php' since it is an ajax request so to wait for the response I have taken a variable called flag(initialized with 'false'). When the response is processed I set the flag as 'true'. But, there is something is wrong with this script because the page freezes. But I cannot debug the script so please help me.
$('.login-form').submit(function(){
var flag = false , tag;
if(login.check() === false){
return false;
}
else{
$.post('check.php',{
"username":$('#username1').val(),
"password":$('#password1').val()
},function(data){
var obj = JSON.parse(data);
if(obj.status === false){
var server_alert = document.getElementsByClassName('server-alert')[0];
server_alert.innerHTML = obj.error;
server_alert.className = server_alert.className.replace('display-hide','');
tag = false;
flag = true;
}
else if(obj.status === true){
tag = true;
flag = false;
}
});
}
while(flag != true);
return tag;
})
I have this partially working code. What it suppose to do is to check for existing email address in database. If no email exist then return true;
$(document).ready(function() {
var email_check = 0;
var checking_html = '<img src="http://i.imgur.com/Y8wXAZp.gif" /> Checking...';
var characters_error = 'Minimum amount of chars is 6';
//when button is clicked
$('.register').click(function(){
//run the character number check
if($('#email').val().length < 1){
$('#email_result').html(characters_error);
return false;
}
else{
//else show the cheking_text and run the function to check
$('#email_result').html(checking_html);
alert(check_email_availability());
}
});
});
//function to check email availability
function check_email_availability(){
//get the email
var email = $('#email').val();
//use ajax to run the check
$.post("check_email.php", { email: email },
function(result){
email_check = 0;
//if the result is 1
if(result == 1){
//show that the email is available
email_check = 1;
}else{
email_check = 0;
}
});
if (email_check == 1){
return true;
}else{
return false;
}
}
Now, the problem is if current state is false, when I enter an email that is not available in the db and click button, I still get false alert, and when the next time I click button I get true alert. For some reason the function execute bottom code first (checking email_check value) and after that it execute the function. Why is that? What is wrong with my code? How can I make it execute function and then check the email_check value whether 1 or not?
I would change this to put an ajax success callback on your check function something along the lines of.
success: function (data, status, xhr ) {
myFunctionShowEmailSuccess();
},
error: function (xhr, status, error) {
myFunctionShowEmailFailure();
}
Try doing this.
//function to check email availability
function check_email_availability(){
//get the email
var email = $('#email').val();
//use ajax to run the check
$.post("check_email.php", { email: email },
function(result){
email_check = 0;
//if the result is 1
if(result == 1){
//show that the email is available
return true;
}else{
return false;
}
});
}
Here is the code I have now.
function ns_check()
{
var login = document.forms['vpnForm'].login.value;
var passwd = document.forms['vpnForm'].passwd.value;
var domainname = login.indexOf("\\")
if (domainname = - 1){
window.alert(_("You need to enter a domain name")); return false;
}
if (login == ""){
window.alert(_("You need to enter login name")); return false;
}
if (passwd == ""){
window.alert(_("You need to enter passwd")); return false;
}
return true;
}
When you do not use a backslash in the login box it does popup an alert window, but it is empty.
Any help would be appreciated.
if (domainname = - 1)
should be
if (domainname === - 1)