...

View Full Version : External Variables in Form Code



jimjam
10-08-2008, 03:22 AM
I've posted several topics and eventually found the form i need. http://simplythebest.net/scripts/DHTML_scr...ascript_49.html (http://simplythebest.net/scripts/DHTML_scripts/javascripts/javascript_49.html). I need this code to load the the Product Prices and Names from a more simple seperate document so it's easier to modify as products and their prices change regularly.
java script:

if (form.Productline1[0].selected){
Line1_print= "None [$0]";
Line1_flag=0;
}
if (form.Productline1[1].selected){
Line1_flag =84.95;
Line1_print="PlanMagic Business [$84.95]";
}
else if (form.Productline1[2].selected){
Line1_flag =99.95;
Line1_print="PlanMagic Marketing [$99.95]";
}etc...
Form:

<td>Productline 1:<br>
<select name="Productline1">
<option selected>Select
<option>PlanMagic Business [$84.95]
<option>PlanMagic Marketing [$99.95]
</select>etc...

So basically where do i start and what do i need to do to get "Line1_flag" and Line1_print" to retrieve their values from a seperate document and also markup to the form code.

Sorry i am new to this and not so good at creating codes from scratch so any help would be appreciated.

rangana
10-08-2008, 03:25 AM
Please show us the complete markup and scripts involved.

jimjam
10-08-2008, 03:30 AM
This is the head section, Javascript

<SCRIPT LANGUAGE="JavaScript">
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
var called=false;
var T_Price=0;
var Line1_flag;
var Line1_print="";
var Line2_flag;
var Line2_print;
var Line3_flag;
var Line3_print;
var Line4_flag;
var Line4_print;
var Line5_flag;
var Line5_print;
var Line6_flag;
var Line6_print;
function compute(form){
called=true;
//-------Productline 1----------
if (form.Productline1[0].selected){
Line1_print= "None [$0]";
Line1_flag=0;
}
if (form.Productline1[1].selected){
Line1_flag =84.95;
Line1_print="PlanMagic Business [$84.95]";
}
else if (form.Productline1[2].selected){
Line1_flag =99.95;
Line1_print="PlanMagic Marketing [$99.95]";
}
else if (form.Productline1[3].selected){
Line1_flag =144.95;
Line1_print="Finance Pro [$144.95]";
}
else if (form.Productline1[4].selected){
Line1_flag =199.95;
Line1_print="PlanMagic Hotel [$199.95]";
}
else if (form.Productline1[5].selected){
Line1_flag =139.95;
Line1_print="PlanMagic Restaurant [$139.95]";
}
else if (form.Productline1[6].selected){
Line1_flag =499.95;
Line1_print="All Software [$499.95]";
}
//-------Productline 2----------
if (form.Productline2[0].selected){
Line2_flag=0;
Line2_print="None [$0]";
}
if (form.Productline2[1].selected){
Line2_flag=150;
Line2_print="Product 1 [$150]";
}
if (form.Productline2[2].selected){
Line2_flag=200;
Line2_print="Product 2 [$200]";
}
if (form.Productline2[3].selected){
Line2_flag=300;
Line2_print="Product 3 [$300]";
}
//-------Productline 3-----------
if (form.Productline3[0].selected){
Line3_flag=0;
Line3_print="None [$0]";
}
if (form.Productline3[1].selected){
Line3_flag=10;
Line3_print="Product 1 [$10]";
}
if (form.Productline3[2].selected){
Line3_flag=20;
Line3_print="Product 2 [$20]";
}
if (form.Productline3[3].selected){
Line3_flag=30;
Line3_print="Product 3 [$30]";
}
//-------Productline 4-------
if (form.Productline4[0].selected){
Line4_flag=0;
Line4_print="None [$0]";
}
if (form.Productline4[1].selected){
Line4_flag=100;
Line4_print="Product 1 [$100]";
}
if (form.Productline4[2].selected){
Line4_flag=200;
Line4_print="Product 2 [$200]";
}
if (form.Productline4[3].selected){
Line4_flag=300;
Line4_print="Product 3 [$300]";
}
//-------Productline 5-------
if (form.Productline5[0].selected){
Line5_flag=0;
Line5_print="None [$0]";
}
if (form.Productline5[1].selected){
Line5_flag=50;
Line5_print="Product 1 [$50]";
}
if (form.Productline5[2].selected){
Line5_flag=60;
Line5_print="Product 2 [$60]";
}
if (form.Productline5[3].selected){
Line5_flag=70;
Line5_print="Product 3 [$70]";
}
//-------Productline 6-------
if (form.Productline6[0].selected){
Line6_flag=0;
Line6_print="None [$0]";
}
if (form.Productline6[1].selected){
Line6_flag=75;
Line6_print="Product 1 [$75]";
}
if (form.Productline6[2].selected){
Line6_flag=85;
Line6_print="Product 2 [$85]";
}
if (form.Productline6[3].selected){
Line6_flag=95;
Line6_print="Product 3 [$95]";
}
T_Price=Line1_flag+Line2_flag+Line3_flag+Line4_flag+Line5_flag+Line6_flag;
form.T_Price.value=" $ "+ T_Price;
}
function print(form){
if(!called){
compute(form);
}
text = ("<HEAD><TITLE>'Cost Esimator'</TITLE></HEAD>");
text = (text +"<BODY BGCOLOR = '#FFFFFF' ><CENTER><B><FONT SIZE = 3><FONT COLOR=BLUE>Cost Estimator</FONT></FONT></B>");
text= (text +"<br></CENTER>");
text=(text+"<hr>");
text=(text+"<TABLE BORDER =0><TR VALIGN=Top><TD VALIGN=Top>");
text=(text+"<B>Productline1: <BR>Productline2: <BR>Productline3: <BR>Productline4: <BR>Productline5: <BR>Productline6:");
text=(text+"</B></TD><TD>")
text=(text+"<B>"+ Line1_print+"<BR>"+ Line2_print+"<BR>"+ Line3_print+"<BR>");
text=(text+ Line4_print+"<BR>"+ Line5_print+"<BR>"+ Line6_print+"<BR>");
text=(text+"<TD></TR></TABLE><hr>");
text=(text+"<B><FONT COLOR=RED>Total Cost:</FONT>"+" $"+T_Price);
text=(text+"<BR><BR><FONT SIZE=-1><FONT COLOR=Gray>To print, choose File and Print.</FONT></FONT>");
text=(text+"</body></html>");
msgWindow=window.open("","displayWindow","toolbar=no,width=375,height=250,directories=no,status=yes,scrollbars=yes,resize=no,menubar=yes")
msgWindow.document.write(text)
msgWindow.document.close()
}
</SCRIPT>

And this is the Form section.

<form method="post">
<table cellpadding="4" bgcolor="#EAE8E8">
<tr>
<td>Productline 1:<br>
<select name="Productline1">
<option selected>Select
<option>PlanMagic Business [$84.95]
<option>PlanMagic Marketing [$99.95]
<option>Finance Pro [$144.95]
<option>PlanMagic Hotel [$199.95]
<option>PlanMagic Restaurant [$139.95]
<option>All software [$499.95]
</select></td>
<td>Productline 2:<br>
<select name="Productline2">
<option selected>Select
<option>Product 1 [$150]
<option>Product 2 [$250]
<option>Product 3 [$350]
</select></td>
<td>Productline 3:<br>
<select name="Productline3">
<option>Select
<option>Product 1 [$10]
<option>Product 2 [$20]
<option>Product 3 [$30]
</select></td>
</tr>
<tr>
<td>Productline 4:<br>
<select name="Productline4">
<option>Select
<option>Product 1 [$100]
<option>Product 2 [$200]
<option>Product 3 [$300]
</select></td>
<td>Productline 5:<br>
<select name="Productline5">
<option>Select
<option>Product 1 [$50]
<option>Product 2 [$60]
<option>Product 3 [$70]
</select></td>
<td>Productline 6:<br>
<select name="Productline6">
<option>Select
<option>Product 1 [$75]
<option>Product 2 [$85]
<option>Product 3 [$95]
</select></td>
</tr>
<tr>
<td colspan="3">
<table cellpadding="2">
<tr>
<td><br>
<input type="BUTTON" name="Price" value="Update Price" onclick="compute(this.form)">
<input type="text" size="13" name="T_Price" value></td>
<td valign="top"><br>
<input type="BUTTON" name="Print_data" value="Print Preview" onclick="print(this.form)"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
Sorry theirs a lot of excess coding their this is just a template from another website that I need to modify.

rangana
10-08-2008, 03:34 AM
...and it's working fine at my end.

Mind elaborating a little further about the problem you're experiencing right now?

jimjam
10-08-2008, 03:44 AM
Sorry i wasn't clear, it works fine. I was hoping you could help me in making the Products Names and Prices read from a seperate document to make it easier to maintain.

So the "Line1_Print" and "Line1_flag" values for each line are determined in a seperate hopefully more simple document. I'm just not sure on how to achieve this. I'm thinking a seperate document will hold all the different product and price variables so that i can simply update them when needed.

rangana
10-08-2008, 03:46 AM
Use Server-side. Try PHP include() statement (http://us.php.net/include/).

jimjam
10-08-2008, 03:57 AM
So can this be used with my previous code, if i make a seperate Serverside PHP script



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum