|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
java script function is not working
HI
I have two fields in my form , 'status' and 'allocate' . what i want to do is if i have value in field 'allocate' and submint the form , i should get the warning if value in field is Complete or Uncomplete i have done this by defining this function Code:
function Form1_Validator(staff)
{
if (((document.staff.allocate.value!= "") &&(document.staff.status.value == "Complete"))
||((document.staff.allocate.value!= "") &&(document.staff.status.value == "Uncomplete") ))
{
alert("Please choose the call status.");
document.staff.status.focus();
}
and i call that method on submission Code:
<input type=submit name=submit value=Add onClick="Form1_Validator(this.form)";> but even if i have value in the 'allocate' field and value 'complete' in 'status' field i dont get any message. I have tried this functions with staff.status.value instead of document.staff.status but it is not working i have tried onsubmit() in the form as well but i cannot get the result. I have another function in the same page which let me open new window and i can fillin the value in 'allocate' field from the child window but problem is when i place the both function like this Code:
<script language="JavaScript" type="text/JavaScript">
function openNewWin($call_ref){
args="width=600,height=400,resizable=no,scrollbars=yes,s tatus=0";
window.open("allocate.php?call_ref="+$call_ref,"Newwin",args);
}
function Form1_Validator(staff)
{
if ( ((document.staff.allocate.value!= "") &&(document.staff.status.value == "Complete"))
||((document.staff.allocate.value!= "") &&(document.staff.status.value == "Uncomplete")) )
{
{alert("Please choose the call status.");
document.staff.status.focus();
return false;
}
return (true);
}
</script>
i cannot open the window as function openNewWin($call_ref) stops workingas well and i get 'error in page ' at the botton. that is why i am placing both functions in separate <script> tags final version of my code is this Code:
<?php session_start();
session_register("who");
session_register("ref"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitle</title>
<link REL="stylesheet" TYPE="text/css" HREF="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function openNewWin($call_ref){
args="width=600,height=400,resizable=no,scrollbars=yes,s tatus=0";
window.open("allocate.php?call_ref="+$call_ref,"Newwin",args);
}
</script>
<script language="JavaScript" type="text/JavaScript">
function Form1_Validator(staff)
{
if ( ((staff.allocate.value!= "") &&(staff.status.value == "Complete"))
||((staff.allocate.value!= "") &&(staff.status.value == "Uncomplete")) )
{
{alert("Please choose the call status.");
staff.status.focus();
return false;
}
return (true);
}
</script>
</head>
<body>
<?
include 'db.php';
include 'welcome.php';
$staf_ref =$_SESSION["ref"];
// Define post fields into simple variables
$company_ref =$HTTP_GET_VARS['company_ref'];
$time = $_POST['time'];
$allocate = $_POST['allocate'];
$information = $_POST['information'];
$problem = $_POST['problem'];
$solution = $_POST['solution'];
$archive = $_POST['archive'];
$status = $_POST['status'];
$submit = $_POST['submit'];
/* time when the page was loaded */
$firstTime=$_POST['firstTime'];
function add_detail(){
/* *********************************** */
global $staf_ref;
global $company_ref;
/* CREATE THE CALL ID*/
$sql = mysql_query("delete FROM c_call WHERE
staf_ref ='".$staf_ref."' and company_ref ='".$company_ref."' and solution IS NULL
and problem IS NULL")
or die (mysql_error());
/* **************************** */
/* CREATE THE CALL ID*/
$sql = mysql_query("INSERT INTO c_call(staf_ref,company_ref)
VALUES('$staf_ref','$company_ref')")
or die (mysql_error());
/* **************************** */
/* ****get the call id back**** */
$sqlquery = "SELECT * FROM c_call WHERE
staf_ref ='".$staf_ref."' and company_ref ='".$company_ref."' and problem IS NULL";
if ($result = mysql_query($sqlquery))
{ } else {
echo mysql_error();
exit();
};
$row=mysql_fetch_array($result );
$call_ref=$row["call_ref"];
/* ******************************** */
?>
<form name="staff" onSubmit="return Form1_Validator(this.form)" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" >
<?php echo " <!--DWLayoutTable-->
<table width=500 align=center>
<tr><td>Inform me of solution</td><td><input name=information type=radio value=1></td>
<td><input name=firstTime type=hidden value=strtotime(now)</td> </tr></table>
<table width=500 align=center>
<tr>
<TD height=32 colspan=2 valign=top class=exp><strong>Staff Ref</strong></TD>
<td colspan=4 valign=top class=exp>$staf_ref</td>
</tr>
<tr>
<TD><strong>Company Ref</strong></TD> <td width=5></td>
<td colspan=4 valign=top class=exp> $company_ref
</td>
</tr>
<tr><td></td><td width=5></td><td>
<select name=status>
<option value=Complete>Complete</option>
<option value=Allocated>Allocated</option>
<option value=Uncomplete>Uncomplete</option>
</select></td></tr>";
/* *********Allocate the call to senior member *************** */
echo "<tr><td><a href="javascript:openNewWin($call_ref)">allocate</a></td><td></td><td><input name=allocate type=text id=allocate value=$allocate></td></tr>";
/* ************************* */
echo "<tr>
<td width=112 height=36 valign=top class=exp><strong>Call Ref</strong></td>
<td width=5></td>
<td colspan=4 valign=top class=exp>
<input name=call_ref type=text id=call_ref value=$call_ref>
</td>
</tr>
<tr>
<td height=26 valign=top class=exp><strong>Problem</strong></td>
<td><div align=center>
<textarea name=problem rows=5 cols=50>$problem</textarea>
</div></td>
<td width=14 ></td>
<td ></td>
</tr>
<tr>
<td height=26 valign=top class=exp><strong>Solution</strong></td>
<td><div align=center>
<textarea rows=5 cols=50 name=solution >$solution</textarea>
</div></td>
<td width=14 ></td>
<td ></td>
</tr>
</table>"; ?>
<table align=center>
<tr>
<td height=39 colspan=2 align=center valign=middle >
<input type=submit name=submit value=Add ></td>
</tr>
</table> <?php
echo "</form>";}
/* Let's strip some slashes in case the user entered
any escaped characters. */
/* Do some error checking on the form posted fields */
if (!isset($submit)) {add_detail(); // Show the form
}
else
{
echo $company_ref;
echo "<br>";
echo $staf_ref;
echo "<br>";
$sqlquery = "SELECT * FROM c_call WHERE
staf_ref ='".$staf_ref."' and company_ref ='".$company_ref."' and problem IS NULL";
if ($result = mysql_query($sqlquery))
{ } else {
echo mysql_error();
exit();
};
if ($row=mysql_fetch_array($result ))
{ echo "hi1";
echo "<br>";
$call_ref=$row["call_ref"];
echo $call_ref;
echo "<br>";
/************************************************** **
Define the archive value according to status
************************************************** **/
if ($status='Allocated') {$archive='1';}
if ($status='Uncomplete') {$archive='2';}
if ($status='Complete') {$archive='3';}
/*************************** ****************************************
perform subtraction to get the difference (in seconds) between times
************************************************** *******************/
$lastTime=strtotime(now);
$timeDiff=($lastTime-$firstTime)/60;
$date= date("M d, Y",time())." ".date("H:i",time());
$date1= date("M d, Y", time());
/* **************************************** */
/* *************************** */
$sql = "UPDATE c_call SET
solution='$solution',
status='$status',
problem='$problem',
date='$date',
reopen='$information',
archive='$archive',
time='$date1'
where call_ref='".$call_ref."'";
/************************************ */
if ($allocate!="") {
$sql_call = mysql_query("INSERT INTO c_allocate(call_ref,allocate)
VALUES('$call_ref','$allocate')")
or die (mysql_error()); }
/* ******************************************** */
if ($result = mysql_query($sql)) {} else {
echo "$sql <br>";
echo mysql_error();
echo "<br>";
exit;
};
echo 'Call details have been added.';
echo ' This call lasted for $timeDiff seconds';
/* ********************** */
}
}
?>
</body>
</html>
Can anyone help me out please thank you |
|
#2
|
|||
|
|||
|
RE: java script function is not working
looks like a sytax error is causing the function to fail. in the code you posted, here is the validate function:
function Form1_Validator(staff) { if ( ((staff.allocate.value!= "") &&(staff.status.value == "Complete")) ||((staff.allocate.value!= "") &&(staff.status.value == "Uncomplete")) ) { {alert("Please choose the call status."); staff.status.focus(); return false; } return (true); } Note the extra opening curly bracket before the alert...should not be there. It should look like this function Form1_Validator(staff){ if ( ((staff.allocate.value!= "") && (staff.status.value == "Complete")) || ((staff.allocate.value!= "") && (staff.status.value == "Uncomplete")) ) { alert("Please choose the call status."); staff.status.focus(); return false; } return (true); } ther than that the function looks fine. |
|
#3
|
|||
|
|||
|
RE: java script function is not working
thank u
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > java script function is not working |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|