PDA

View Full Version : Script Issue


jsorenson3
07-07-2006, 10:36 PM
I have a form that I have put the Dynamic Drive script into. I have a script that I put in that checked for the required fields and that one worked. I also put a different one by Dynamic Drive that would disable the submit button until the user checks the box. Because of legal reason , we need it for the person to first scroll thru the terms before having the submit button enabled

Please take a look at the following code. It gives me a parse error. Its not liking this part
//Set id of Terms Textarea:
var termsId='terms'
//Set Agree Form Name:
var agreeform='agreeform'
//Set Agree Form Agree Checkbox Name:
var agreecheck='agreecheck'

If i remove the apostrophe it works fine but then i get another document.forms error.

If I paste all the code into a regular document and call it testing.html or whatever it works fine

Is there anywhere special i need to move the script for it to work


<?php
$contentHTML .= '
<div class="header">Master Account Information</div>
Please fill out the Master Account Information form (dealer application) and Master Dealer Agreement completely. If you have questions on any item, please contact KeriAnne at 1-800-234-3663 Ext. 212, Judi at Ext. 171 or the Credit Department at Ext. 352.
<form method="POST" action="newdlr_app2.php" onsubmit="return formCheck(this);">
<form name="agreeform" onSubmit="return defaultagree(this)">



<br>
<script type="text/javascript" language="JavaScript">
function formCheck(formobj){
// name of mandatory fields
var fieldRequired = Array("Company_Name", "Contact_Person", "Address_1", "City", "State", "Zip", "Area_Code", "Telephone_Number", "Applicant_Email", "States_Business", "Year_Company_Started", "Fed_ID", "Products_Sold", "Average_Sale_Price", "Units_Sold", "Licensed_State", "Type_of_Business", "How_Heard", "Owner_1_Name", "Owner_1_Home_Address", "Owner_1_City", "Owner_1_State", "Owner_1_Zip", "Owner_1_Social_Security_Number", "Owner_1_Home_Phone", "Owner_1_Percent_Owned", "Owner_1_Years_Owned", "Unsatisfied_Judgements", "Bankruptcy_Declared");
// field description to appear in the dialog box
var fieldDescription = Array("Company Name", "Contact Person", "Address", "City", "State", "Zip", "Area Code", "Telephone Number", "Email Address", "States you do business in", "Year Company Started", "Federal ID #", "Products Sold", "Average Sale Price", "Units Sold", "Licensed in each state", "Type of Business", "How Did you hear about us?", "Owner 1 Name", "Owner 1 Home Address", "Owner 1 City", "Owner 1 State", "Owner 1 Zip Code", "Owner 1 Social Security Number", "Owner 1 Home Phone", "Owner 1 Percent Owned", "Owner 1 Years Owned", "Are there any Unsatisfied Judgements?", "Bankruptcy Declared?");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
if (obj.type == null){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
continue;
}
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<head>
<script type="text/javascript">

//"Accept terms" form submission- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
//Modified Here by jscheuer1 in http://www.dynamicdrive.com/forums
//to also require scrolling to the bottom of the terms.

//Set id of Terms Textarea:
var termsId='terms'
//Set Agree Form Name:
var agreeform='agreeform'
//Set Agree Form Agree Checkbox Name:
var agreecheck='agreecheck'

/////////////No Need to Edit Below/////////

var ckSc, termsH, textA, checkobj, ok=0

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit"){
if(ok&&checkobj.checked)
tempobj.disabled=0
else {
if (checkobj.checked)
alert('At Least Read the Terms!')
tempobj.disabled=1
checkobj.checked=0
}
}
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}

function checkScroll() {
if (textA.scrollTop>=termsH-10){
ok=1
clearInterval(ckSc)
}
}

function getH(){
document.forms[agreeform][agreecheck].checked=false
textA=document.all? document.all[termsId] : document.getElementById(termsId)
textA.scrollTop=0
var scT=scT1=scT2=textA.scrollTop
while (scT==scT1){
scT1+=1000
textA.scrollTop+=1000
scT=textA.scrollTop
}
textA.scrollTop=scT2
termsH=scT
ckSc=setInterval("checkScroll();",20)
}

if (document.all||document.getElementById)
onload=getH

</script>
</head>

<!-- company info -->
<div align="center" class="element">
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<th colspan="2"><span class="subhead">Company Information</span></th>
</tr>
<tr>
<td><span class="required">Company Name</span></td><td><input type="text" size="25" name="Company_Name"></td>
</tr>
<tr>
<td>Contact Person</td><td><input type="text" size="15" name="Contact_Person"></td>
</tr>
<tr>
<td>Title</td><td><input type="text" size="15" name="Title"></td>
</tr>
<tr>
<td>Address</td><td><input type="text" size="25" name="Address_1"><br><input type="text" size="25" name="Address_2"></td>
</tr>
<tr>
<td>City</td><td><input type="text" size="25" name="City"></td>
</tr>
<tr>
<td>State</td><td><input type="text" size="2" maxlength="2" name="State"></td>
</tr>
<tr>
<td>Zip</td><td><input type="text" size="5" maxlength="5" name="Zip"></td>
</tr>
<tr>
<td>Area Code and Telephone Number</td><td><input type="text" size="3" maxlength="3" name="Area_Code">&nbsp&nbsp<input type="text" size="8" maxlength="10" name="Telephone_Number"></td>
</tr>
<tr>
<td>Fax</td><td><input type="text" size="3" maxlength="3" name="Fax_Area_Code">&nbsp&nbsp<input type="text" size="8" maxlength="10" name="Fax_Telephone_Number"></td>
</tr>
<tr>
<td>Email</td><td><input type="text" size="25" name="Applicant_Email"></td>
</tr>
<tr>
<td>List States You Do Business In</td><td><input type="text" size="25" name="States_Business"></td>
</tr>
<tr>
<td>Are You Licensed In Each State</td><td><select name="Licensed_State"><option>Select One</option><option>Yes</option><option>No</option></select></td>
</tr>
<tr>
<td>Year Company Started</td><td><input type="text" size="4" maxlength="4" name="Year_Company_Started"></td>
</tr>
<tr>
<td>Fed ID#</td><td><input type="text" size="15" name="Fed_ID"></td>
</tr>
<tr>
<td>Manufactuer/Brand<br>of Products Sold</td><td><input type="text" size="15" name="Products_Sold"></td>
</tr>
<tr>
<tr>
<td>Average Sale Price of Equipment</td><td><input type="text" size="15" name="Average_Sale_Price"></td>
</tr>
<tr>
<td>Number of Units Sold per Month</td><td><input type="text" size="15" name="Units_Sold"></td>
</tr>
<td>Type of Business</td><td><select name="Type_of_Business"><option>Select One</option><option>Proprietorship</option><option>Partnership</option><option>Corporation</option><option>LLC</option><option>Other</option></select></td>
</tr>
</tr>
<td>How Did You Hear About Us</td><td><select name="How_Heard"><option>Select One</option><option>Direct Mail</option><option>Manufacturer Referral</option><option>Magazine Ad</option><option>Trade Show</option><option>BFC Website</option><option>Dealer Referral</option><option>Other Website</option><option>Other</option></select></td>
</tr>
<tr>
<td>If Magazine Ad, Please Specify Magazine Name</td><td><input type="text" size="25" name="Choice_Magazine_Ad"></td>
</tr>
<tr>
<td>If Trade Show, Please Specify Trade Show Attended</td><td><input type="text" size="25" name="Choice_Trade_Show"></td>
</tr>
<tr>
<td>If Other, Please Specify</td><td><input type="text" size="25" name="Choice_Other"></td>
</tr>

</table>
</div>

';
//OWNERSHIP
for ($i=1; $i<=3; $i++) {
$contentHTML .= '
<br>
<div align="center" class="element">
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<th colspan="2"><span class="subhead">Ownership Information ('.$i.')</span></th>
</tr>
<tr>
<td>Name</td><td><input type="text" size="25" name="Owner_'.$i.'_Name"></td>
</tr>
<tr>
<td>Home Address</td><td><input type="text" size="25" name="Owner_'.$i.'_Home_Address"></td>
</tr>
<tr>
<td>City</td><td><input type="text" size="25" name="Owner_'.$i.'_City"></td>
</tr>
<tr>
<td>State</td><td><input type="text" size="2" maxlength="2" name="Owner_'.$i.'_State"></td>
</tr>
<tr>
<td>Zip</td><td><input type="text" size="5" maxlength="5" name="Owner_'.$i.'_Zip"></td>
</tr>
<tr>
<td>Home Phone Number</td><td><input type="text" size="12" maxlength="12" name="Owner_'.$i.'_Home_Phone"></td>
</tr>
<tr>
<td>Social Security Number</td><td><input type="text" size="9" maxlength="9" name="Owner_'.$i.'_Social_Security_Number"><br><span class="note">No Dashes Please</span></td>
</tr>
<tr>
<td>Percent Owned</td><td><input type="text" size="3" maxlength="3" name="Owner_'.$i.'_Percent_Owned">%</td>
</tr>
<tr>
<td>Years Owned</td><td><input type="text" size="3" maxlength="3" name="Owner_'.$i.'_Years_Owned"></td>
</tr>
</table>
</div>';
}
//QUESTIONS
$contentHTML .= '
<br>
<div align="center" class="element">
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<th colspan="2"><span class="subhead">Judgements/Bankruptcy</span></th>
</tr>
<tr>
<td width="300">Are there any unsatisfied judgements against the business or any of its officers or owners?</td>
<td><input type="radio" size="25" name="Unsatisfied_Judgements" value="Yes"> Yes<br><input type="radio" size="25" name="Unsatisfied_Judgements" value="No"> No</td>
</tr>
<tr>
<td width="300">Has the business or any of its officers or owners declared bankruptcy in the past 10 years?</td>
<td><input type="radio" size="25" name="Bankruptcy_Declared" value="Yes"> Yes<br><input type="radio" size="25" name="Bankruptcy_Declared" value="No"> No</td>
</tr>
<tr>
<td width="400"colspan="2"><span class="subhead">If you answered &quot;Yes&quot; to any of these questions, please supply details below:</span><br><textarea name="Judgements_Bankruptcy_Details"cols="40" rows="5"></textarea></td>
</tr>
</table>
</div>
';


//FINANCIAL/TRADE
$ref_cats = array("Financial","Trade");
while ( list($foo,$ref_cat) = each($ref_cats) ) { //(<span style=\"color: red;\">Required</span>)
for ($i=1; $i<=3; $i++) {
$contentHTML .= '
<br>
<div align="center" class="element">
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<th colspan="2"><span class="subhead">Reference - '.$ref_cat.' ('.$i.')</span></th>
</tr>
<tr>
<td>Name</td><td><input type="text" size="25" name="'.$ref_cat.'_Ref_'.$i.'_Name"></td>
</tr>
<tr>
<td>Address</td><td><input type="text" size="25" name="'.$ref_cat.'_Ref_'.$i.'_Address"></td>
</tr>
<tr>
<td>City</td><td><input type="text" size="25" name="'.$ref_cat.'_Ref_'.$i.'_City"></td>
</tr>
<tr>
<td>State</td><td><input type="text" size="2" maxlength="2" name="'.$ref_cat.'_Ref_'.$i.'_State"></td>
</tr>
<tr>
<td>Zip</td><td><input type="text" size="5" maxlength="5" name="'.$ref_cat.'_Ref_'.$i.'_Zip"></td>
</tr>
<tr>
<td>Area Code and Phone Number</td><td><input type="text" size="3" maxlength="3" name="'.$ref_cat.'_Ref_'.$i.'_Area_Code">&nbsp&nbsp<input type="text" size="8" maxlength="10" name="'.$ref_cat.'_Ref_'.$i.'_Phone"></td>
</tr>
<tr>
<td>High Balance</td><td>$<input type="text" size="25" name="'.$ref_cat.'_Ref_'.$i.'_High_Balance"></td>
</tr>
<tr>
<td>Present Balance</td><td>$<input type="text" size="25" name="'.$ref_cat.'_Ref_'.$i.'_Present_Balance"></td>
</tr>
</table>
</div>';
}
}
$contentHTML .= '
<br>
<span class="note">
The information contained in this statement is provided for the purpose of establishing a credit referral relationship with Bay Finance, a division of Aqua
Finance, Inc. (hereafter referred to as AFI) on behalf of the dealer. The dealer understands that AFI is relying on
the information provided herein in deciding to grant or continue credit to customers of the dealer who are seeking credit
from AFI. The dealer represents and warrants that the information provided is true and complete and that AFI may
consider these statements as continuing to be true and correct until a written notice of change is given to AFI by the
dealer. AFI is authorized to make all inquiries it deems necessary to verify the accuracy of the statements made herein,
and to determine the dealer’s credit worthiness. By submitting this application the dealer grants permission to those to whom inquiry is made to
provide all information requested by AFI. AFI is authorized to release information about its experiences with the dealer.<br><br>
<textarea id="terms" cols=50 rows=5 wrap=virtual>
Test Test Test
</textarea><br>
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>I agree to the above terms</b><br>
<input type="Submit" value="Submit!" disabled>
<script type="text/javascript">
document.forms[agreeform][agreecheck].checked=false
</script>

</form>';
?>


Thanks

GJay
07-07-2006, 10:41 PM
From looking at the code with colour-highlighting, you should have noticed bits like the following:

$var='
//[...]
var termsId='terms'
//Set Agree Form Name:
var agreeform='agreeform'
//Set Agree Form Agree Checkbox Name:
var agreecheck='agreecheck'
//[...]
';

that need escaping.

jsorenson3
07-07-2006, 10:44 PM
Escaping. I'm sorry, still fairly new and have figured a majority out on my own. Not sure what you mean. Can you please clarify

Thanks

GJay
07-07-2006, 10:47 PM
The above should be:

$var='
//[...]
var termsId=\'terms\'
//Set Agree Form Name:
var agreeform=\'agreeform\'
//Set Agree Form Agree Checkbox Name:
var agreecheck=\'agreecheck\'
//[...]
';

(or use double-quotes instead).
When the parser comes across a single quote, it assumes you're ending the string. You need the \ in front to tell it that you mean a literal-quote, and not to interpret it.

jsorenson3
07-07-2006, 10:54 PM
Now I am getting

Parse error: parse error, unexpected T_VAR in /www/websites/bayf5425/webspace/secure/newdealer_form2.php on line 77
Which is


$var='

var termsId="terms"
//Set Agree Form Name:
var agreeform="agreeform"
//Set Agree Form Agree Checkbox Name:
var agreecheck="agreecheck"
';

Fou-Lu
07-07-2006, 11:57 PM
You imbedding that $var into the variable already?
Anyway, try Heredoc style, may work more easily. Perhaps you should review your document structure as well, as I see form elements appearing before the head elements, and no doctype & html elements at all.