Advertisement

08.19.2008 at 03:20AM PDT, ID: 23659002
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

javascript validation code not working on input field

Asked by gwh2 in JavaScript, PHP Scripting Language, Macromedia Dreamweaver

Tags:

Hi everyone,

I've used the javascript behaviour in Dreamweaver to validate a form. I've validated an input text field and also a text area field, but when I test it in a browser and press the submit button without filling in any of the form, the validating javascript error message that pops up only refers to the text area field that was validated and not the text input field. The code for the input field is as follows:

                <td class="label">Title</td>
                <td class="right"><input value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" type="text" name="title" id="title" class="widebox" /></td>

I can't work out why it's not working for the above field. I've included the code for the whole page below and wondered if someone could help me troubleshoot this. There is php embedded in the code also so I don't know if this is contributing to the problem.

Can someone help?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
<?php require_once('../Connections/connSub.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ($_POST) {
  $pub_date = getTheDate();
  if (strpos($pub_date, 'Error') === 0) {
    $error['date'] = $pub_date;
    }
  }
  
  if ($_POST && !isset($error)) {
$_POST['pub_date'] = $pub_date;
 
 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addArticle")) {
  $insertSQL = sprintf("INSERT INTO articles (title, author, pub_date, article) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['author'], "int"),
                       GetSQLValueString($_POST['pub_date'], "date"),
                       GetSQLValueString($_POST['article'], "text"));
 
  mysql_select_db($database_connSubscribe, $connSubscribe);
  $Result1 = mysql_query($insertSQL, $connSubscribe) or die(mysql_error());
 
  $insertGoTo = "menu.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
}
 
mysql_select_db($database_connSubscribe, $connSubscribe);
$query_rstAuthors = "SELECT authors.author_ID, CONCAT(authors.firstname, ' ', authors.surname) AS name FROM authors ORDER BY authors.surname";
$rstAuthors = mysql_query($query_rstAuthors, $connSubscribe) or die(mysql_error());
$row_rstAuthors = mysql_fetch_assoc($rstAuthors);
$totalRows_rstAuthors = mysql_num_rows($rstAuthors);
?><!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"><!-- InstanceBegin template="/Templates/hthadmin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Add an article</title>
<!--[if IE 7]>
<link href="../css/win_ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
 
<!--[if lt IE 7]>
<link href="../css/win_ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
 
 
<!-- InstanceEndEditable -->
 
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../javascript/topmenu.js"></script>
<style type="text/css" media="screen">
@import url("../css/topnav.css");
</style>
 
 
<script type="text/javascript" src="../Templates/p7pm/p7popmenu.js"></script>
<link href="../css/mainInner.css" rel="stylesheet" type="text/css" />
 
<!-- InstanceBeginEditable name="head" -->
 
 
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<!-- InstanceEndEditable -->
 
</head>
 
 
<body onload="P7_initPM(1,8,1,-20,10)">
<?php
if (isset($error)) {
  foreach ($error as $message) {
    echo '<p class="warning">'.$message.'</p>';
	}
  }
if(get_magic_quotes_gpc()) {
	foreach ($_POST as $key => $value) {
		$temp = stripslashes($value);
		$_POST[$key] = $temp;
		}
	}
?>
<div class="shadow">
  <div id="frame">
    <div id="header"> 
      <h3><img src="../images/phone.gif" alt="" />Call for an appointment: (02) xxxx xxxx</h3>
	</div>
	  <div id="navtop">
	    <!--<ul id="p7PMnav">
          <li><a href="../index.php">Home</a></li>
	      <li><a href="../about_us.php">About Us</a></li>
	      <li><a href="../downloads.php">Downloads</a></li>
	      <li><a href="../price_list.php">Price List</a></li>
	      <li class="recommend"><a href="../rec_Practitioners.php" class="recommend">Recommended Practitioners</a></li>
	      <li><a href="../contact.php" id="noborder">Contact Us</a></li>-->
	      <!--[if lte IE 6]><style>#p7PMnav a{height:1em;}#p7PMnav li{height:1em;}#p7PMnav ul li{float:left;clear:both;width:100%}</style><![endif]-->
	      <!--[if IE 6]><style>#p7PMnav ul li{clear:none;}</style><![endif]-->
        <!--</ul>-->
	  </div>
	  <div id="enclose">
	    <div id="leftside"><!-- InstanceBeginEditable name="Content" -->
        <div id="columnMainInner">
	        <h1>Add an article  </h1>
           	
			<form action="<?php echo $editFormAction; ?>" method="POST" name="addArticle" id="addArticle" onsubmit="MM_validateForm('title','','R','article','','R');return document.MM_returnValue">
			<table>
              <tr>
                <td class="label">Title</td>
                <td class="right"><input value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" type="text" name="title" id="title" class="widebox" /></td>
              </tr>
              <tr>
                <td class="label">Author</td>
                <td class="right"><select name="author" id="author">
                    <option value="0">Choose an Author</option>
<?php
do {  
?>
                    <option value="<?php echo $row_rstAuthors['author_ID']?>"><?php echo $row_rstAuthors['name']?></option>
                    <?php
} while ($row_rstAuthors = mysql_fetch_assoc($rstAuthors));
  $rows = mysql_num_rows($rstAuthors);
  if($rows > 0) {
      mysql_data_seek($rstAuthors, 0);
	  $row_rstAuthors = mysql_fetch_assoc($rstAuthors);
  }
?>
                </select>
                </td>
              </tr>
              <tr>
                <td class="label">Publication date </td>
                <td class="right"><input value="<?php if (isset($_POST['pub_date'])) echo $_POST['pub_date']; ?>" name="pub_date" type="text" id="pub_date" /></td>
              </tr>
              <tr>
                <td class="label">Delete article </td>
                <td class="right">No 
      <input name="kill_article" type="radio" value="N" checked="checked" /> 
      Yes 
      <input name="kill_article" type="radio" value="Y" /></td>
              </tr>
              <tr>
                <td class="label">Article</td>
                <td class="right"><textarea name="article" id="article"><?php echo isset($_POST['article']) ? $_POST['article'] : ''; ?></textarea></td>
				
				
              </tr>
              <tr>
                <td class="label">&nbsp;</td>
                <td class="right"><input type="submit" name="Submit" value="Add Article" /></td>
              </tr>
            </table>
            <input type="hidden" name="MM_insert" value="addArticle">
		  </form>
        </div>
		    <!-- InstanceEndEditable -->
	      <div id="columnLeft">
			    <ul>
			      	  <li><a href="admin_home.php">Admin Home</a></li>
				      <li><a href="add_user.php">Add  administrator</a></li>
				      <li><a href="add_article.php">Add article</a></li>
				      <li><a href="list_articles.php">List articles</a></li>
					  <li><a href="add_author.php">Add author</a></li>
				      <li><a href="list_authors.php">List authors</a></li>
				      <li><a href="list_subscribers.php">List subscribers</a></li>
		    </ul>
		<p>&nbsp; </p>
		<p>&nbsp; </p>
		<p>&nbsp; </p>
		<p>&nbsp; </p>
	      </div>
	    </div><div class="clear"></div>
	  </div>
	  <div id="footerinner"> © copyright 2008. All Rights Reserved  <!--&nbsp;|&nbsp; <a href="../terms_and_conditions.php">Terms and Conditions</a>  &nbsp;| &nbsp; <a href="../privacy_policy.php">Privacy Policy</a>  &nbsp; |&nbsp;  <a href="../contact.php">Contact Us</a>--></div>
  </div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rstAuthors);
 
function getTheDate() {
  $retVal = ''; // make sure return value empty
  // if date entered, assign to shorter variable for simplicity and process
  if (!empty($_POST['pub_date'])) {
    $d = $_POST['pub_date'];
    if (strpos($d,'/') === false) { // check if slashes used
      $retVal = 'Error: Date should be in DD/MM/YYYY format';
      }
    else { // if slashes, split into array
      $d = explode('/',$d);
      // remove any leading zeros
	  // following two lines for US style
     // $month = intval($d[0]);
     // $dayNum = intval($d[1]);
	  // if European style required, uncomment the next two lines
	  $dayNum = intval($d[0]);
	  $month = intval($d[1]);
      $year = $d[2];
 
    if (!checkdate($month,$dayNum,$year)) { // check validity of date
      $retVal = 'Error: Date not valid';
      }
    else { // if OK, format for MySQL
      $retVal = $year.'-'.$month.'-'.$dayNum;
      }
    }
  }
  else { // if no date set, use today's date
    $retVal = date('Y-m-d');
    }
  return $retVal; // return formatted date or error message
}
 
?>
[+][-]08.19.2008 at 03:49AM PDT, ID: 22258561

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 04:36AM PDT, ID: 22258782

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 05:23AM PDT, ID: 22259082

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 05:41AM PDT, ID: 22259192

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 05:51AM PDT, ID: 22259243

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 06:03AM PDT, ID: 22259335

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 06:32AM PDT, ID: 22259544

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 06:42AM PDT, ID: 22259645

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 06:50AM PDT, ID: 22259715

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaScript, PHP Scripting Language, Macromedia Dreamweaver
Tags: javascript, php, xhtml
Sign Up Now!
Solution Provided By: shirazti
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.19.2008 at 07:17AM PDT, ID: 22259989

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 08:08AM PDT, ID: 22260470

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 08:24AM PDT, ID: 22260650

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628