I have included my html code for many other eyes to help me figure this out.
Javascript works. One side by on_click and other side by on_change.
Issue is when calling my vbscript.
This is a modified version of a working script that just displayed some data a client wanted to see, but now they want to calculate it.
I think I am pretty close but my mind is just so burnt that I could you some helpful advise as to what I am missing.
Thank you
CHAZ
<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<style type="text/css">
input { float: center; }
</style>
<script type="text/javascript">
function Mcalc(){
PRC = 0
AVG = 0
if (document.MARGIN.PPrice.value > "")
{ PRC = document.MARGIN.PPrice.value };
document.MARGIN.PPrice.value = eval(PRC);
if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);
MRG = (PRC - AVG) / PRC * 100;
document.MARGIN.NMargin.value = dm(eval(MRG));
}
function Pcalc(){
MRG = 0
AVG = 0
if (document.MARGIN.PMargin.value > "")
{ MRG = document.MARGIN.PMargin.value };
document.MARGIN.PMargin.value = eval(MRG);
if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);
PRC = AVG/(1-MRG/100);
document.MARGIN.NPrice.value = dm(eval(PRC));
}
function dm(amount) {
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
</script>
</HEAD>
<BODY onLoad="document.MARGIN.txtItem.focus()">
<script language="vbscript" type="text/vbscript">
Function RETRIEVE()
dim dbconnection, sqlrs, itemno, ITEM
Const CONNECT_STRING = "provider=SQLOLEDB.1;Presist Security info=True;User ID=sa;Initial Catalog=DEMODATA;Data Source=SERVER;password=PASSWORD"
Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
Set dbconnection = createobject("ADODB.connection")
Set sqlrs = createobject("ADODB.Recordset")
dbconnection.open CONNECT_STRING
Itemno = document.MARGIN.txtItem.value
sqlrs.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&Itemno&"' AND LOC_ID='MAIN'", CONNECT_STRING
If sqlrs.EOF Then
Wscript.Echo "Invalid Item. Please Re-Enter."
Else
document.MARGIN.Description.value = sqlrs("DESCR")
document.MARGIN.AvgCost.value = sqlrs("AVG_COST")
document.MARGIN.Price.value = sqlrs("PRC_1")
document.MARGIN.Margin.value = sqlrs("MARGIN")
END IF
sqlrs.close
dbconnection.close
End Function
</script>
<H3>Margin Calculator</H3><HR>
<FORM method=post action='' NAME="MARGIN">
<table>
<tr>
<td align="left">Item Number:</td>
<td align="left"><INPUT NAME="txtItem" TYPE="TEXT" SIZE="10" autofocus></td>
<td align="left">Item Description: </td>
<td align="left"><INPUT NAME="DESCRIPTION" TYPE="TEXT" SIZE="30" readonly tabindex="-1"></td>
</tr>
<tr>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Retrieve Item" onclick ="call RETRIEVE()"></td>
<td align="left"> </td>
<td align="left">Average Cost: </td>
<!-- <td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10" readonly tabindex="-1" ></td> -->
<td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10"></td>
</tr>
<tr>
<td align="left"><BR> </td>
</tr>
<tr>
<td align="left">Current Price: </td>
<td align="left"><INPUT NAME="Price" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">Current Margin: </td>
<td align="left"><INPUT NAME="Margin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>
<tr>
<td align="left"><BR> </td>
</tr>
<tr>
<td align="left">Proposed Price: </td>
<td align="left"><INPUT NAME="PPrice" TYPE="TEXT" SIZE="10" onchange="Mcalc()"></td>
<td align="left">Proposed Margin: </td>
<td align="left"><INPUT NAME="PMargin" TYPE="TEXT" SIZE="10"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Margin" onclick ="Mcalc()" ></td>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Price" onclick ="Pcalc()" ></td>
</tr>
<tr>
<td align="left"><BR> <BR></td>
</tr>
<tr>
<td align="left">New Margin: </td>
<td align="left"><INPUT NAME="NMargin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">New Price: </td>
<td align="left"><INPUT NAME="NPrice" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>
<tr>
<td align="left"><BR> <BR><BR></td>
</tr>
<tr>
<td align="left"><INPUT TYPE="RESET" STYLE="width:100" VALUE="Clear Form" onclick="document.MARGIN.txtItem.focus()"></td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Copy Data" onclick="document.MARGIN.txtNPrice.select()"></td>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Exit" onclick="self.close()"></td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
Javascript works. One side by on_click and other side by on_change.
Issue is when calling my vbscript.
This is a modified version of a working script that just displayed some data a client wanted to see, but now they want to calculate it.
I think I am pretty close but my mind is just so burnt that I could you some helpful advise as to what I am missing.
Thank you
CHAZ
<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<style type="text/css">
input { float: center; }
</style>
<script type="text/javascript">
function Mcalc(){
PRC = 0
AVG = 0
if (document.MARGIN.PPrice.value > "")
{ PRC = document.MARGIN.PPrice.value };
document.MARGIN.PPrice.value = eval(PRC);
if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);
MRG = (PRC - AVG) / PRC * 100;
document.MARGIN.NMargin.value = dm(eval(MRG));
}
function Pcalc(){
MRG = 0
AVG = 0
if (document.MARGIN.PMargin.value > "")
{ MRG = document.MARGIN.PMargin.value };
document.MARGIN.PMargin.value = eval(MRG);
if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);
PRC = AVG/(1-MRG/100);
document.MARGIN.NPrice.value = dm(eval(PRC));
}
function dm(amount) {
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
</script>
</HEAD>
<BODY onLoad="document.MARGIN.txtItem.focus()">
<script language="vbscript" type="text/vbscript">
Function RETRIEVE()
dim dbconnection, sqlrs, itemno, ITEM
Const CONNECT_STRING = "provider=SQLOLEDB.1;Presist Security info=True;User ID=sa;Initial Catalog=DEMODATA;Data Source=SERVER;password=PASSWORD"
Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
Set dbconnection = createobject("ADODB.connection")
Set sqlrs = createobject("ADODB.Recordset")
dbconnection.open CONNECT_STRING
Itemno = document.MARGIN.txtItem.value
sqlrs.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&Itemno&"' AND LOC_ID='MAIN'", CONNECT_STRING
If sqlrs.EOF Then
Wscript.Echo "Invalid Item. Please Re-Enter."
Else
document.MARGIN.Description.value = sqlrs("DESCR")
document.MARGIN.AvgCost.value = sqlrs("AVG_COST")
document.MARGIN.Price.value = sqlrs("PRC_1")
document.MARGIN.Margin.value = sqlrs("MARGIN")
END IF
sqlrs.close
dbconnection.close
End Function
</script>
<H3>Margin Calculator</H3><HR>
<FORM method=post action='' NAME="MARGIN">
<table>
<tr>
<td align="left">Item Number:</td>
<td align="left"><INPUT NAME="txtItem" TYPE="TEXT" SIZE="10" autofocus></td>
<td align="left">Item Description: </td>
<td align="left"><INPUT NAME="DESCRIPTION" TYPE="TEXT" SIZE="30" readonly tabindex="-1"></td>
</tr>
<tr>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Retrieve Item" onclick ="call RETRIEVE()"></td>
<td align="left"> </td>
<td align="left">Average Cost: </td>
<!-- <td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10" readonly tabindex="-1" ></td> -->
<td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10"></td>
</tr>
<tr>
<td align="left"><BR> </td>
</tr>
<tr>
<td align="left">Current Price: </td>
<td align="left"><INPUT NAME="Price" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">Current Margin: </td>
<td align="left"><INPUT NAME="Margin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>
<tr>
<td align="left"><BR> </td>
</tr>
<tr>
<td align="left">Proposed Price: </td>
<td align="left"><INPUT NAME="PPrice" TYPE="TEXT" SIZE="10" onchange="Mcalc()"></td>
<td align="left">Proposed Margin: </td>
<td align="left"><INPUT NAME="PMargin" TYPE="TEXT" SIZE="10"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Margin" onclick ="Mcalc()" ></td>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Price" onclick ="Pcalc()" ></td>
</tr>
<tr>
<td align="left"><BR> <BR></td>
</tr>
<tr>
<td align="left">New Margin: </td>
<td align="left"><INPUT NAME="NMargin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">New Price: </td>
<td align="left"><INPUT NAME="NPrice" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>
<tr>
<td align="left"><BR> <BR><BR></td>
</tr>
<tr>
<td align="left"><INPUT TYPE="RESET" STYLE="width:100" VALUE="Clear Form" onclick="document.MARGIN.txtItem.focus()"></td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Copy Data" onclick="document.MARGIN.txtNPrice.select()"></td>
<td align="left"> </td>
<td align="left"> </td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Exit" onclick="self.close()"></td>
</tr>
</table>
</FORM>
</BODY>
</HTML>