25
rated 0 times
[
30]
[
5]
/ answers: 1 / hits: 24715
/ 13 Years ago, fri, august 5, 2011, 12:00:00
I have a JavaScript function as follows:
function popup(username) {
var req = createAjaxObject();
var message = prompt(Message:,);
if(message != ){
req.onreadystatechange = function() {
if (req.readyState == 4) {
alert(req.responseText);
}
}
req.open('POST','getmessage.php',true);
req.setRequestHeader(Content-type,application/x-www-form-urlencoded);
req.send(username= + username +&message=+message);
} else {
alert(Please enter a message);
}
}
When the Cancel
button is hit, the form is still processed through getmessage.php
. Any way to have the Cancel
button do nothing?
EDIT:
Here is the way this function is called:
<?php
mysqlLogin();
$username = $_COOKIE['sqlusername'];
$sql = mysql_query(SELECT username FROM `users` WHERE username!='$username');
if(mysql_num_rows($sql) != 0) {
echo <table class='usertable' align='center'>;
while($row = mysql_fetch_array($sql)){
$username = $row['username'];
echo <tr><td><center> . $row['username'] . </center></td><td> <a href='#' onClick=popup('$username');>Send Message</a></td></tr>;
}
echo </table>;
} else {
echo <center>No users found!</center>;
}
?>
The PHP
script its linked to:
<?php
$id = rand(1,1500);
$poster = $_POST['username'];
$message = $_POST['message'];
$to = $_COOKIE['sqlusername'];
require('functions.php');
mysqlLogin();
$sql = mysql_query(INSERT INTO `messages` VALUES ('$id','$message','$to','$poster',''));
if($sql){
echo Message sent!;
} else {
echo Woops! Something went wrong.;
}
?>
More From » prompt