Jump to content

Having problems with javascript code


tmharrison

Recommended Posts

I have my main website. www.mysite.com it has a tour number field on it, and it is working fine, however i would like to have javascript alerts when they either leave the field blank or the tour number doesn't exist in the database.  I have the alerts on my php page already.

 

anyway, i am ok with the way that it is, however, when i click the OK on the javascript alert message it continues to go onto my gotoTour.php script.  (which is listed below)

 

 

<?php
ob_start();
if (!empty($_POST['id_num'])) {

require_once ('/home/virttcom/public_html/VHDdb/mysql_connect.php');

// Clean the $_POST['id_num'] to avoid sql injection
if(get_magic_quotes_gpc()) {
	$_POST['id_num'] = stripslashes($_POST['id_num']);
}
$_POST['id_num'] = mysql_real_escape_string($_POST['id_num']);

$q = "SELECT url FROM Tours WHERE id_num='{$_POST['id_num']}'";

$get_url = mysql_query($q) or die("There was a problem with the query: $q" . mysql_error());

if (mysql_num_rows($get_url) > 0) {
	$rw = mysql_fetch_assoc($get_url);
	$url = $rw['url'];

	// Redirect the user
	header("location:$url");
} else {
		echo "<script language=\"javascript\"> alert('We do not carry this Virtual Tour, call your Agent and ask them to use Virtual Tours'); </script>"; 
}
} else {
		echo "<script language=\"javascript\"> alert('Virtual Tour Numbers are six numeric digits only. Please check your number and try again.'); </script>";
}
ob_end_flush();
?>

 

 

How can I get it to stop continuing to go to this php page, and just show the alert message on my main page www.mysite.com

 

Much appreciated, i've been messing with this all night now, i have tried everything been on every javascript site there is to figure it out, i am stuck.

 

Thanks again for your help

 

Tina

Link to comment
Share on other sites

Well one option is to check it before it is submitted using AJAX. If you check it after it has already been submitted, then do something like this:

echo "<script language=\"javascript\"> alert('We do not carry this Virtual Tour, call your Agent and ask them to use Virtual Tours'); 
history.go(-1); 
// or 
document.location.href = 'wherever.php';
</script>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.