Page 1 of 1
Javascript error message
Posted: Sat Jan 24, 2004 7:03 pm
by mwphurst
Is there a way to get a javascript error to pop up when information returned from a data base querry is false?
I want to check a data base to see if the information matches, if not pop up an error message instead of an html page. I got the idea from a similar function in a script. All I have been able to find is mostly mouse or window events.
Posted: Sun Jan 25, 2004 10:03 am
by web_angel
You mean just a simple if/then statement and an alert window? Assuming that you know how to do database queries
Like this:
<script language="JavaScript">
if(!database_query) {
alert("Sorry Query is false. Try again");
}
</script>
Does that help?
Posted: Sun Jan 25, 2004 12:21 pm
by mwphurst
Not exactly. It's after I query. I want to compare values entered in a form to values in the data base.
Code: Select all
if ($est_option_id != $group_value_id) { I want an error here if they don't match.... }
Posted: Sun Jan 25, 2004 1:38 pm
by Gen-ik
Just use PHP to compare the form values with the database and then if you need to pop-up a window echo some JavaScript to the page.
Is there any reason why you need to compare form and database values in JavaScript?
Posted: Sun Jan 25, 2004 2:09 pm
by mwphurst
I'm trying to avoid popping up a different window. I like the error messages that you can use with javascript. They just pop up a warning, like this.
Code: Select all
<a href="#" onClick="javascript:alert('$la_no_del_sorry_val')"><font color="#990000">$la_inv_del</font></a>
I know how to get it to open a new window using php, if returned false. Is there a way to activate the javascript without and event from the client?
Posted: Sun Jan 25, 2004 4:57 pm
by Gen-ik
Ok, in that case just echo() the JavaScript to the page if the values don't match... but adding an error to the page as actual text (HTML) is a lot nicer and won't get on peoples nerves as much as an alert box would.
Code: Select all
<?php
// The values don't match so add some JS to the page
$errorText = "The values don't match!";
echo <<< END
<script type="text/javascript">
window.onload = function () { alert("{$errorText}"); }
</script>
END;
?>
Posted: Sun Jan 25, 2004 5:59 pm
by mwphurst
Hey thanks Gen-ik. I figured it had to be something like the onload event, but since I don't know java at all, I couldn't get it to work. I guess I should spend a little time learning how to write functions.
Thanks again.
Michael