i really dunno what i miss or what's wrong with my codes.
it would only work when you hit the "Post" button on the second try.
i think it has something to do with my GUI, coz if i would just test the form named "fields" the javascript would work. but if i would run it with the GUI, it would no longer work.
here's my whole PHP file.
..sorry if its long.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FAQ manager</title>
<link rel="stylesheet" type="text/css" href="design.css" />
<script type="text/javascript" src="checkFields.js"></script>
</head>
<?php
include("connector.php");
$query=mysql_query("select * from qa");
$row = mysql_fetch_assoc($query);
$query1=mysql_query("select * from categories");
?>
<body background="1.gif">
<div id="container">
<div id="header"></div>
<div id="heading"><font color="#FFFFCC" face="Copperplate Gothic Bold" size="6">FAQ</font><font color="#FFFFCC" size="7" face="Blackadder ITC"> manager</font></div>
<div id="tabs">
<div align="left"><span class="style8"><a class="for_tabs" href="FAQ.php">Home</a> | <a class="for_tabs" href="inbox.php">Inbox</a> </span></div>
</div>
<div id="search">
<table width="244">
<tr>
<td>
<form action="search.php" method="post"><font color="#FFFFCC" face="Andalus" size="3">Search:</font>
<input type="text" name="search">
<input type="image" src="go.png" alt="Submit" /></form>
</td>
</tr>
</table>
</div>
<div id="faqs_label"></div>
<div id="faq_text"><font color="#336600" size="4">Add FAQ</font></div>
<div id="faqs">
<center>
<br>
<table border="1">
<form method="post" action="adding_FAQ_check.php" name="fields" onSubmit="return checkFields(this)">
<tr>
<td>Question:</td>
<td><textarea name="question" rows="1" cols="50"></textarea></td>
</tr>
<tr>
<td>Answer:</td>
<td><textarea name="answer" rows="7" cols="50"></textarea></td>
</tr>
<tr>
<td>Category:</td>
<td><select name="category">
<?php while($row1 = mysql_fetch_assoc($query1)) { ?>
<option value=<?php echo $row1['cat_num'];?>><?php echo $row1['category']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="Post"></td>
</form>
</tr>
</table>
</center>
</div>
<div id="category_label"></div>
<div id="categories">
<table width="270">
<?php while($row1 = mysql_fetch_assoc($query1)){?>
<tr>
<td width="180"> <a class="hype" href="categories.php?num=<?php echo $row1["cat_num"]; ?>#<?php echo $row1["cat_num"]; ?>"><font color="#9B004E"><?php echo $row1['category']; ?></fontO></a>
</td>
</tr>
<?php } ?>
</table>
</div>
<div id="category_text"><font color="#336600" size="4">categories</font></div>
<div id="cat_button">
<table>
<tr>
<td><form action="new_category.php" method="post">
<input name="submit" type="submit" value="Add Category" />
</form>
</td>
<td><form action="view_categories.php" method="post">
<input name="submit" type="submit" value="View Categories" />
</form>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
and my javascript
function checkFields()
{
if(fields.question.value == "")
{
alert('Fill up Question field.')
fields.question.focus()
return false
}
if(fields.answer.value == "")
{
alert('Fill up Answer field.')
fields.answer.focus()
return false
}
}
thanks for your time. :)