Here is the code for profile.php in , in the submit button the onclick event doesnt working tell me where the mistakes are there the javascript function doesnt loading at all
<?php include("./inc/header.inc.php"); ?>
<?php include("./inc/connect.inc.php"); ?>
<?php
$username = "";
$firstname = "";
if(isset($_GET['u'])){
$username = mysql_real_escape_string($_GET['u']);
if(ctype_alnum($username)){
$check = mysql_query("SELECT username, first_name FROM users where username='$username' limit 1");
$userCount = mysql_num_rows($check);
if($userCount == 1){
while($row = mysql_fetch_assoc($check)){
$username = $row['username'];
$firstname = $row['first_name'];
}
}else{
echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\"> ";
exit();
}
}
}
?>
<div id="Wrapper">
<div id="right">
<div class="PostForm">
<textarea id="post" name="post" rows="5" cols="180"></textarea>
<!-- here is the submit button -->
<input type="submit" name="send" onclick="javascript:send_post()" value="post" style="background-color:#DCE5EE;float:right;border:1px solid #666; color:#666;height:73px; width: 65px;">
</div>
<div class="profilePosts">YOur Posts will go Here</div>
</div>
<div id="left">
<img src="" height="250" width="200" alt="<?php echo $username; ?>'s Profile" title="<?php echo $username; ?>'s Profile" />
<br>
<div class="textHeader"><?php echo $username; ?>'s Profile</div>
<div class="profileLeftSideContent">Some Content about this persons profile..</div>
<div class="textHeader"><?php echo $username; ?>'s Profile</div><br>
<div class="profileLeftSideContent">
<img src="#" height="50" width="40" />
<img src="#" height="50" width="40" />
<img src="#" height="50" width="40" />
<img src="#" height="50" width="40" />
<img src="#" height="50" width="40" />
<img src="#" height="50" width="40" />
<img src="#" height="50" width="40" />
<img src="#" height="50" width="40" />
</div>
</div>
</div>
<?php include('./inc/footer.inc.php'); ?>
the code for header.in.php file , i mentioned sorce of the javascript file correctly
<!Doctype html>
<html>
<head>
<title>..</title>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<script type="text/javascript" src="../js/main.js"></script>
</head>
the code for javascript file is , this function is doesnt loading while the submit button in the profile.php is called ..
function send_post() {
var hr = new XMLHttpRequest();
var url = "my_message_parse.php";
var fn = document.getElementById("post").value;
var vars = "post="+fn;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
hr.send(vars);
document.getElementById("status").innerHTML = "processing...";
}
is there any method withour using the javascript and please sepcify the error in the submit button of profile.php ,thanks for reply
The problem is it is a submit button so it submits the form onclick. You need to prevent that from happening.
<input type="submit" name="send" onclick="send_post(); return false;" ...
A better way would be to add the event unobtrusively and use preventDefault