Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript submitting forms x2

    Thanks in advance! Everytime i enter details on this one particular form i would like it to create two records in the database.

    Whats the easiest way of doing this.

    Below is the code for the form in question:



    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 & "?" & 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_connPWPR_STRING
    MM_editTable = "MainTable"
    MM_editRedirectUrl = "PropertiesForRentMenu.html"
    MM_fieldsStr = "EntryDate|value|MoreInfo|value|Trabsaction|value|Resort|value|HouseStyle|value|Title|value|FirstNam e|value|HomePhone|value|Surname|value|Mobile|value|HomeMail|value|Address1|value|Address2|value|Town |value|County|value|PostCode|value|Country|value|PlotNo|value|Rental Required|value|STATUS|value|Lowest Rent|value|Price on Web|value|CompDate|value"
    MM_columnsStr = "EntryDate|',none,''|MoreInfo|',none,''|TRANSACTION|',none,''|Resort|',none,''|HouseStyle|',none,''| Title|',none,''|FirstName|',none,''|HomePhone|',none,''|Surname|',none,''|Mobile|',none,''|HomeMail| ',none,''|Address1|',none,''|Address2|',none,''|Town|',none,''|County|',none,''|PostCode|',none,''|C ountry|',none,''|PlotNo|',none,''|RequdPrice|',none,''|STATUS|',none,''|AvailableToPay|',none,''|Req udPriceNumeric|none,none,NULL|CompDate|',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
    %>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" 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>
    </head>

    <body leftmargin="0" topmargin="0">
    <p><a href="../Index.htm"><img src="../Images/PWPR_Heading.jpg" width="744" height="65" border="0"></a></p>
    <p><font color="#2D2D6B" size="4"><strong><font face="Arial, Helvetica, sans-serif">Add
    Basic information about a Rental Property</font></strong></font></p>
    <form action="<%=MM_editAction%>" method="POST" name="form1" onSubmit="MM_validateForm('RequdPriceNumeric','','NisNum');return document.MM_returnValue">
    <table width="646" border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td height="39"><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Date:</font></div></td>
    <td><input name="EntryDate" type="text" id="EntryDate" maxlength="20">
    <font face="Verdana, Arial, Helvetica, sans-serif" color="navy" size="1"><b><br>
    As this - &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <script language="JavaScript">

    <!-- Begin
    var days=new Array(8);
    days[1]="Sunday";
    days[2]="Monday";
    days[3]="Tuesday";
    days[4]="Wednesday";
    days[5]="Thursday";
    days[6]="Friday";
    days[7]="Saturday";
    var months=new Array(13);
    months[1]="January";
    months[2]="February";
    months[3]="March";
    months[4]="April";
    months[5]="May";
    months[6]="June";
    months[7]="July";
    months[8]="August";
    months[9]="September";
    months[10]="October";
    months[11]="November";
    months[12]="December";
    var time=new Date();
    var lday=days[time.getDay() + 1];
    var lmonth=months[time.getMonth() + 1];
    var date=time.getDate();
    var year=time.getYear();
    var hour=time.getHours();
    var min=time.getMinutes();
    if (year < 2000) // Y2K Fix, Isaac Powell
    year = year + 1900; // http://onyx.idbsu.edu/~ipowell
    document.write( date + " " +lmonth + " ");
    document.write( year );
    // End -->
    </script>
    </b></font></td>
    <td colspan="2" rowspan="4"> <div align="left"></div>
    <div align="right"></div>
    <div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;&nbsp;&nbsp;&nbsp;More
    Information - including rental dates available:</font><br>
    &nbsp;&nbsp;
    <textarea name="MoreInfo" cols="45" rows="5" id="textarea"></textarea>
    </div></td>
    </tr>
    <tr>
    <td height="39"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Type
    of Transaction:</strong></font></div></td>
    <td width="32%" bgcolor="#003399"> <font color="#000000" size="3" face="Arial, Helvetica, sans-serif"><strong><font color="#CCCCCC">&nbsp;&nbsp;Property
    for Rent</font>
    <input name="Trabsaction" type="hidden" id="Trabsaction" value="Property for Rent">
    </strong></font></td>
    </tr>
    <tr>
    <td height="45"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Resort:</font></div></td>
    <td><select name="Resort" id="Resort">
    <option value="Mar Menor">Mar Menor</option>
    <option value="La Torre">La Torre</option>
    <option value="La Manga Club">La Manga Club</option>
    <option value="Roda Golf">Roda Golf</option>
    <option value="El Valle">El Valle</option>
    <option value="Hacienda Del Alamo">Hacienda Del Alamo</option>
    <option value="La Tercia">La Tercia</option>
    <option value="Los Alcazares Area">Los Alcazares Area</option>
    <option value="La Union / El Algar Area">La Union / El Algar Area</option>
    <option value="Senoria De Roda">Senoria De Roda</option>
    <option value="Cartagena City">Cartagena City</option>
    <option value="Others">Others</option>
    <option value="La Manga Strip">La Manga Strip</option>
    <option value="Lo Pagan / San Pedro">Lo Pagan / San Pedro</option>
    </select></td>
    </tr>
    <tr>
    <td height="31"><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Style
    of Property: </font></div></td>
    <td><input name="HouseStyle" type="text" id="HouseStyle" size="45" maxlength="45"></td>
    </tr>
    <tr>
    <td height="31">&nbsp;</td>
    <td><font color="#2F3071" size="2" face="Arial, Helvetica, sans-serif"><strong>Rental
    Poperty - Owner Information:- </strong></font></td>
    <td width="24%">&nbsp;</td>
    <td><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
    </font></div></td>
    </tr>
    <tr>
    <td width="9%" height="31"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Title:</font></div></td>
    <td colspan="2"> <input name="Title" type="text" id="Title2" size="6" maxlength="6">
    <div align="right"></div></td>
    <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;
    </font></td>
    </tr>
    <tr>
    <td height="30"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">First
    Name: </font></div></td>
    <td><input name="FirstName" type="text" id="FirstName" size="40" maxlength="40">
    <div align="right"></div></td>
    <td><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Home
    Phone:&nbsp;</font></div></td>
    <td><div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
    <input name="HomePhone" type="text" id="HomePhone7" onBlur="MM_validateForm('HomePhone7','','R');return document.MM_returnValue" size="35" maxlength="50">
    </font></div></td>
    </tr>
    <tr>
    <td height="29"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Surname:</font></div></td>
    <td><input name="Surname" type="text" id="Surname" size="40" maxlength="40">
    <div align="right"></div></td>
    <td><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Mobile:</font></div></td>
    <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
    <input name="Mobile" type="text" id="Mobile6" size="35" maxlength="50">
    </font></td>
    </tr>
    <tr>
    <td height="39"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"></font></div></td>
    <td> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">E-mail
    address:&nbsp;</font></div></td>
    <td colspan="2"><div align="right"></div>
    <div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
    <input name="HomeMail" type="text" id="HomeMail5" size="50" maxlength="50">
    </font></div></td>
    </tr>
    <tr>
    <td height="31"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Contact
    Address 1:</font></div></td>
    <td colspan="3"> <input name="Address1" type="text" id="Address1" size="70" maxlength="70">
    <div align="right"></div></td>
    </tr>
    <tr>
    <td height="30"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Address
    2: </font></div></td>
    <td colspan="3"> <input name="Address2" type="text" id="Address2" size="70" maxlength="70">
    <font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    </tr>
    <tr>
    <td height="29"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Town:</font></div></td>
    <td colspan="2"> <input name="Town" type="text" id="Town" size="30" maxlength="30">
    <font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    <td rowspan="3" valign="bottom"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font>
    </td>
    </tr>
    <tr>
    <td height="32"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">County:</font></div></td>
    <td colspan="2"> <input name="County" type="text" id="County" size="25" maxlength="25">
    <font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    </tr>
    <tr>
    <td height="33"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Post/Zip
    Code:</font></div></td>
    <td colspan="2"> <input name="PostCode" type="text" id="PostCode" size="15" maxlength="15">
    <font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    </tr>
    <tr>
    <td height="42"><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Country:</font></div></td>
    <td><input name="Country" type="text" id="Country3" size="30" maxlength="30">
    </td>
    <td><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Plot
    Number: </font></div></td>
    <td><input name="PlotNo" type="text" id="PlotNo" size="10" maxlength="10"></td>
    </tr>
    <tr>
    <td height="42"><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">weekly
    Rental Required by Client in Euros:</font></div></td>
    <td>€ <input name="Rental Required" type="text" id="PurchasePrice3" size="10" maxlength="10">
    <font color="#0066CC" size="2" face="Arial, Helvetica, sans-serif">
    (This field must contain a Zero or a value)</font></td>
    <td><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>STATUS</strong>:</font></div></td>
    <td bgcolor="#003399"> <select name="STATUS" id="STATUS">
    <option value="Do not show on Site">Do not show on Site</option>
    <option value="Show on Web Site">Show on Web Site</option>
    </select> </td>
    </tr>
    <tr>
    <td height="42"><div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Lowest
    Negotiable Rent:</font></div></td>
    <td><div align="right">
    <input name="Lowest Rent" type="text" id="RequdPrice2" size="10" maxlength="10">
    <font color="0066CC" size="2" face="Arial, Helvetica, sans-serif"><strong>
    Note : This does NOT appear on Web Site</strong></font></div></td>
    <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
    <td bgcolor="#003399"><strong><font color="#666666" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Note:-
    Only when STATUS is set to &quot;Show on Web Site&quot; do properties
    appear on Web.</strong></font></strong></td>
    </tr>
    <tr>
    <td height="54" bgcolor="#006699"> <div align="center"><font color="#CCCCCC" size="1" face="Verdana, Arial, Helvetica, sans-serif">Price
    to appear on Web Site:</font></div></td>
    <td bgcolor="#003399"> <div align="right"><font color="#0066CC" size="2" face="Arial, Helvetica, sans-serif">
    <input name="Price on Web" type="text" id="Price on Web" value="0" size="10" maxlength="10">
    <font color="#666666"> This is the figure that appears on Web
    Site - (This field MUST contain a Zero or a value)</font></font>
    <font color="#666666" size="2" face="Arial, Helvetica, sans-serif"><br>
    <font size="1">(No Comma Separator or you will get a nasty error!)</font></font></div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height="42"> <div align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Property
    first available for Rent:</font></div></td>
    <td><input name="CompDate" type="text" id="CompDate2" size="18" maxlength="18">
    <br> <font face="Verdana, Arial, Helvetica, sans-serif" color="navy" size="1"><b>As
    this - &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <script language="JavaScript">

    <!-- Begin
    var days=new Array(8);
    days[1]="Sunday";
    days[2]="Monday";
    days[3]="Tuesday";
    days[4]="Wednesday";
    days[5]="Thursday";
    days[6]="Friday";
    days[7]="Saturday";
    var months=new Array(13);
    months[1]="January";
    months[2]="February";
    months[3]="March";
    months[4]="April";
    months[5]="May";
    months[6]="June";
    months[7]="July";
    months[8]="August";
    months[9]="September";
    months[10]="October";
    months[11]="November";
    months[12]="December";
    var time=new Date();
    var lday=days[time.getDay() + 1];
    var lmonth=months[time.getMonth() + 1];
    var date=time.getDate();
    var year=time.getYear();
    var hour=time.getHours();
    var min=time.getMinutes();
    if (year < 2000) // Y2K Fix, Isaac Powell
    year = year + 1900; // http://onyx.idbsu.edu/~ipowell
    document.write( date + " " +lmonth + " ");
    document.write( year );
    // End -->
    </script>
    </b></font> </td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit"></td>

    </tr>
    </table>
    <p>&nbsp; </p>
    <p>&nbsp;</p>
    <p>&nbsp; </p>
    <input type="hidden" name="MM_insert" value="form1">
    </form>
    </body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Surely it must just be a case of copying part of the code and repeating it so it repeats itself?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •