Jump to content

Thought I would try again but differently this time


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 Home Debut'); </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

I had to do this for a job not too long ago. if memory serves me, you have to write a javascript function that returns true or false. then when you call the function you need to use the return statement like this:

 

javascript..........................

 

function validate(){

 

  //code for (if the number is good){

  return true

  }else{

  alert('error message');

  return false;

  }

 

}

 

html...............................

 

onClick="return validate()"

 

--------------------------------

 

hope that helps - next time ask in the javascript forum

Link to comment
Share on other sites

I don't think this will work in my situation as i am using the header() function?

 

somehow i need to be able to do this in 1 line of code basically, actually I really don't know at this point.

 

Everything was going really good last night, then of course i want it to do this, and now i can't figure it out.

 

P.S. should i re-do this post in the javascript location?

 

Thanks for your help

 

Tina

Link to comment
Share on other sites

	echo "<script language=\"javascript\"> alert('Virtual Tour Numbers are six numeric digits only. Please check your number and try again.'); window.location='http://www.virtualhomedebut.com'; </script>";

 

This is what I changed it too, yes it seems to be doing better, but it still is going to a white screen first then back to my home page, isn't there a way that it just never moves off of my home page?

 

Thanks so much ProjectFear!

 

Tina

Link to comment
Share on other sites

I have a MySQL database, if they happen to know the listing number and I am the one that has done the virtual tour of the home, then I would create the seperate directory structure on my website, and then install that url in my database, which has the primary field of the listing number.

 

anyway, on my main site i have this field for them to use, however it probably won't be how they access it anyway, it would be just a direct link that they are given or click on from an agents site or mls listing.

 

so, i thought i would put this feature on anyway, it all is working as far as going to the urls that are in my database, my only concern was if they didn't do it correctly, like submit an empty field or possibly an incorrect number, that is were i wanted to do some kind of javascript code that would alert them to this, i really didn't want to create multiple pages for this, if i have to i will but i have seen other sites doing this, and i kind of think it is possible then.

 

anyway, i use the header() function to have the database redirect them to the url when they do type in the correct and/or valid number.

 

I guess i will just have to make a couple more html pages for these types of user errors.

 

unless someone knows of a way to not make it continue the php script that is shown on my original posting.

 

your a peach!

 

Tina

Link to comment
Share on other sites

if you have a submit button and the field is empty i could make it show a javascript error without leaving the page. but checking for a valid tour number would require ajax.

 

so if you have a form that they enter the number post it here, unless you already have, i might have missed it.

Link to comment
Share on other sites

 <form action="gotoTour.php" method="post" name="tours" target="_self">
	          <span class="graytext">
	          <input name="id_num" type="text" class="graytext1" id="textfield"></span><br></br>
	          <label for="Enter"></label>
          	  <input type="image" src="images/enter.jpg" width=76 height=18 border=1 id="Enter">
	            
              </p>
          </form>

 

this is the form code from my index page

 

I sure do appreciate this!

 

If it doesn't work this way

 

I do have a book on ajax hacks write in front of me, i just don't know what i would be looking for!  ha ha

 

Thanks

Link to comment
Share on other sites

here is the alert for the blank id, for anything else you'd need ajax.

 

<script language="javascript">
function blankTour(){
if(document.tours.id_num.value == ''){
alert("You need to enter an ID to view a tour.");
return false;
}else{
return true;
}
}
</script>

<form action="gotoTour.php" method="post" name="tours" target="_self">
<span class="graytext">
<input name="id_num" type="text" class="graytext1" id="textfield"></span><br></br>
<label for="Enter"></label>
<input type="image" src="images/enter.jpg" width=76 height=18 border=1 id="Enter" onclick="javascript: return blankTour()">
</p>
</form>

 

hope that works for you. good luck with the rest.

Link to comment
Share on other sites

That was beautiful, worked perfectly, can i set the position of the alert window?  i think i can, just don't know the syntax.

 

I think this is absolutely great!  Thank you so very much, I had great help last night and it continues on to tonight!

 

also, what are the buzz words that i might need to be looking for in ajax, would you happen to know?

 

Thanks so much, your a peach!

 

Tina

Link to comment
Share on other sites

set the position. i am not sure. i dont think so, as far as i know...

 

ajax...well i wouldnt no the exact words... but there are people that will. i think jesirose is experienced in ajax and there are a few moderators, i think CV, who are experienced as well. there may be others. just wait, they should read this and answer your question. just dont PM them.

Link to comment
Share on other sites

Ok

 

Don't worry about the PM, i have never done that ever, actually don't even know how to do it.

 

always best to just wait.

 

I am looking up the javascript codes now for positioning, seems that it can be done with something like window.open?

 

could i use that function instead of the alert possibly?

Link to comment
Share on other sites

I just saw this thread over on codingforums.com  looked pretty good, i'm too tired to see if this will work or not, but at least it didn't look like it was really that much work

 

You can create a custom alert box using div, layer and tables.
first you create a HTML view similar to an alert box by using any of dov,layers and tables. make the visibility property to hidden when loading.
using javascript make it visible at which ever position you want... and then one more thing... when a default alert box appears we will be able to do any other event on that page... i hope you get my idea... like that you can do when you show your custom alert box by disabling the mouse and keyboard events like the following...

i have tested this code in Internet explorer


<script>

document.onclick=disableEvents
document.oncontextmenu=disableEvents

var ef=0

function showalert()
{

ef=1
var ids
ids=document.getElementById('alert')
ids.style.left=300;
ids.style.top=150;
ids.style.visibility="visible"
}

function disableEvents()
{
if(ef)
return false;
}
</script>


<body>


<div align=center id="alert" style="position:absolute;left:0;top:0;border: 2px solid gray; width:100; height:100;color:red; background-color:black;visibility:hidden;">

<br>Alert Message <br><br><br>

<input type=button name=ok value=0k onclick="ef=0;document.getElementById('alert').style.visibility='hidden';" >

</div>

<br><br><br>
consider there is some error you want show when this link is clicked
<a href="javascript: showalert();">click here</a>

</body>

note: you may wonder how the ok button is working after disabling the onclick event for the whold document... it is because i think the first priority goes to the ok buttons onclick event only after that documents onclick event is checked...

 

I will check this out tomorrow, i have to get to bed now.

 

Thank you again for your help ProjectFear!

 

Worst case is it stays in the middle of the window, and i create one other html page for when they enter a tour number that i don't have!

 

it's better then a kick in the head!

 

Thanks again!

 

Tina

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.