Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > Adobe Web Programming > Dreamweaver (all versions)
| Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Dreamweaver (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2005, 06:13 PM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with textbox validation in Dreamweaver

Hi Imar,

Somehow the form is still submitted without validation the textbox named "Add1" that I have pointed to it. The onclick event did work when i click on Add button to add the new info. Could you please see what went wrong? Thanks

Here the code:

 <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<script language="JavaScript" type="text/JavaScript">
function validForm()
{
  var formField = document.form1.Add1;
  If (formField.value == '')
  {
    alert('Name cannot be empty');
    formField.focus();
    return false;
  }
  return true;
}
</script>

<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

  MM_editConnection = MM_connLawyerLocator_STRING
  MM_editTable = "site"
  MM_editRedirectUrl = "pageConfirm0.asp"
  MM_fieldsStr = "DisID|value|Name|value|Add1|value|Add2|value|City |value|State|value|Country|value|Zip|value"
  MM_columnsStr = "DisID|none,none,NULL|Name|',none,''|Add1|',none,' '|Add2|',none,''|City|',none,''|State|',none,''|Co untry|',none,''|Zip|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")

  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim rsSite
Dim rsSite_numRows

Set rsSite = Server.CreateObject("ADODB.Recordset")
rsSite.ActiveConnection = MM_connLawyerLocator_STRING
rsSite.Source = "SELECT Add1, Add2, City, Country, DisID, Name, O_ID, State, Zip FROM site"
rsSite.CursorType = 0
rsSite.CursorLocation = 2
rsSite.LockType = 1
rsSite.Open()

rsSite_numRows = 0
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>



<title>DCMA Lawyer Locator-Add New DCMA Location</title>

<style type="text/css">
<!--
.style2 {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-size: 14px;
    color: #9B0000;
}
.style3 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}
.style6 {font-family: Arial, Helvetica, sans-serif; font-size: 12; }
.style7 {font-size: 12}
-->
</style>
<style type="text/css">
<!--
.style9 {font-family: "Times New Roman", Times, serif}
-->
</style>
<style type="text/css">
<!--
.style10 {font-family: Arial, Helvetica, sans-serif}
-->
</style>
<style type="text/css">
<!--
.style11 {font-size: 14pt}
-->
</style>
<style type="text/css">
<!--
.style12 {color: #9B0000}
-->
</style>
<style type="text/css">
<!--
.style13 {font-size: 12pt}
-->
</style>
<style type="text/css">
<!--
.style14 {font-size: 10pt}
-->
</style>

<form method="post" action="<%=MM_editAction%>" name="form1">
  <table width="90%" border="0" align="center" cellpadding="1" cellspacing="0">
    <tr>
      <td><span class="style12 style11 style10 style9 style13 style14"><strong>ADD NEW DCMA LOCATION</strong></span></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
  <table bgcolor="#F1F1F1" width="50%" align="center">
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">Organization :</span></td>
      <td><span class="style6">
        <select name="DisID">
          <option value="" selected>--Select One--</option>
          <option value="1">DCMA HQ</option>
          <option value="5">DCMA East</option>
          <option value="7">DCMA West </option>
          <option value="6">DCMA International </option>
          <option value="2">Special Projects</option>
          <option value="3">Contract Disputes Resolution Center</option>
          <option value="4">Contract Integrity Center</option>

      </select>
      </span> </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">New Location Name:</span></td>
      <td><input name="Name" type="text" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">Address1:</span></td>
      <td><input name="Add1" type="text" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">Address2:</span></td>
      <td><input name="Add2" type="text" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">City:</span></td>
      <td><input name="City" type="text" value="" size="20">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">State:</span></td>
      <td><span class="style6">
        <select name="State">
           <option value="">--Select--</option>
               <option value="Unknown">Unknown</option>
               <option value="Alaska">Alaska</option>
               <option value="Alabama">Alabama</option>
               <option value="Arkansas">Arkansas</option>
               <option value="Arizona">Arizona</option>
               <option value="California">California</option>
               <option value="Colorado">Colorado</option>
               <option value="Connecticut">Connecticut</option>
               <option value="District of Columbia">District of Columbia</option>
               <option value="Delaware">Delaware</option>
               <option value="Florida">Florida</option>
               <option value="Georgia">Georgia</option>
               <option value="Hawaii">Hawaii</option>
               <option value="Iowa">Iowa</option>
               <option value="Idaho">Idaho</option>
               <option value="Illinois">Illinois</option>
               <option value="Indiana">Indiana</option>
               <option value="Kansas">Kansas</option>
               <option value="Kentucky">Kentucky</option>
               <option value="Louisiana">Louisiana</option>
               <option value="Massachusetts">Massachusetts</option>
               <option value="Maryland">Maryland</option>
               <option value="Maine">Maine</option>
               <option value="Michigan">Michigan</option>
               <option value="Minnesota">Minnesota</option>
               <option value="Missouri">Missouri</option>
               <option value="Mississippi">Mississippi</option>
               <option value="Montana">Montana</option>
               <option value="North Carolina">North Carolina</option>
               <option value="North Dakota">North Dakota</option>
               <option value="Nebraska">Nebraska</option>
               <option value="New Hampshire">New Hampshire</option>
               <option value="New Jersey">New Jersey</option>
               <option value="New Mexico">New Mexico</option>
               <option value="Nevada">Nevada</option>
               <option value="New York">New York</option>
               <option value="Ohio">Ohio</option>
               <option value="Oklahoma">Oklahoma</option>
               <option value="Oregon">Oregon</option>
               <option value="Pennsylvania">Pennsylvania</option>
               <option value="Rhode Island">Rhode Island</option>
               <option value="South Carolina">South Carolina</option>
               <option value="South Dakota">South Dakota</option>
               <option value="Tennessee">Tennessee</option>
               <option value="Texas">Texas</option>
               <option value="Utah">Utah</option>
               <option value="Virginia">Virginia</option>
               <option value="Vermont">Vermont</option>
               <option value="Washington">Washington</option>
               <option value="Wisconsin">Wisconsin</option>
               <option value="West Virginia">West Virginia</option>
               <option value="Wyoming">Wyoming</option>
        </select>
      </span> </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">Country:</span></td>
      <td><span class="style6">
        <select name="Country">
                <option value="">--Select--</option>
                <option value="Australia">Australia</option>
                <option value="Canada">Canada</option>
                <option value="Egypt">Egypt</option>
                <option value="Germany">Germany</option>
                <option value="Israel">Israel</option>
                <option value="Italy">Italy</option>
                <option value="Japan">Japan</option>
                <option value="Korea">Korea</option>
                <option value="Kuwait">Kuwait</option>
                <option value="Puerto Rico">Puerto Rico</option>
                <option value="Saudi Arabia">Saudi Arabia</option>
                <option value="Singapore">Singapore</option>
                <option value="United Kingdom">United Kingdom</option>
                <option value="USA">United States</option>
        </select>
      </span> </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style3">Zip:</span></td>
      <td><input name="Zip" type="text" value="" size="10">
      </td>
    </tr>

    <tr valign="baseline">
      <td nowrap align="right"><span class="style7"></span></td>
      <td><span class="style7"></span></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"><span class="style7"></span></td>
      <td>
        <div align="left" class="style6">
          <input name="btnAdd" type="submit" onClick="return validForm ();" value="Add">
            <input name="btnCancel" type="button" onClick="javascript:history.back();" value="Cancel">
      </div></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td></td>
    </tr>
  </table>
  <table align="center" width="50%" border="0" cellspacing="0" cellpadding="1">
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right"><a href="menu.asp" class="style3">Return to Menu</a></div></td>
  </tr>
</table>

  <input type="hidden" name="MM_insert" value="form1">
</form>
 
Old October 15th, 2005, 03:13 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Could this be the issue:

function validForm()
{
 var formField = document.form1.Add1;
If (formField.value == '') {
   alert('Name cannot be empty');
   formField.focus();

If with a Capital I? In JavaScript, that should be if.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 17th, 2005, 01:08 PM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you're exactly right.It should be typed "if". Thanks Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox validation rhd110 .NET Framework 2.0 1 March 28th, 2007 02:49 PM
validation in dreamweaver h.phule Dreamweaver (all versions) 1 June 15th, 2006 11:46 AM
textbox validation in c# dhol C# 3 July 22nd, 2005 05:57 AM
TextBox Validation Brettvan1 VB.NET 2002/2003 Basics 1 June 23rd, 2005 08:58 AM
Textbox Validation phudong3da Dreamweaver (all versions) 2 May 9th, 2005 02:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.