manishblr1
Programmer
Hi ,
I have been stuck up with the following issues.
Scenario:
I have a formula box where user enters the formula for example :
(plant1*2+plant2*3) and then user clicks on validate button.
I am replacing plant1/plant2 variables by 1 and trying to get the output as 5. But its giving NaN. I know that the above formula is a string . But i want to know is there any way we can achieve the output as number when forumla is given by the user.
Thanks in advance.
I have been stuck up with the following issues.
Scenario:
I have a formula box where user enters the formula for example :
(plant1*2+plant2*3) and then user clicks on validate button.
I am replacing plant1/plant2 variables by 1 and trying to get the output as 5. But its giving NaN. I know that the above formula is a string . But i want to know is there any way we can achieve the output as number when forumla is given by the user.
Code:
<HTML>
<Title>Consumption Booking</Title>
<script language="javascript">
//definition of global variables
var plantList = new Array();
plantList[0]='';
function plantSelectedFromList(){
if(document.getElementById('myPlantListDropdown').value =="Select Plant"){
//do nothing
}
else{
var selectedPlant = document.getElementById('myPlantListDropdown').value;
if(plantList[0].length==0)
plantList[0]= plantList[0]+selectedPlant;
else
plantList[0]= plantList[0]+","+selectedPlant;
var formulaTextarea = consumptionBookingForm.myFormulaTextarea.value;
formulaTextarea = formulaTextarea + selectedPlant+" ";
consumptionBookingForm.myFormulaTextarea.value = formulaTextarea;
}
}
//function to validate quantity calculator formula
function validateQuantityFormula(){
alert(consumptionBookingForm.myFormulaTextarea.value);
var tempQuantityCalc= consumptionBookingForm.myFormulaTextarea.value;
var listOfPlants=plantList[0].split(",");
for(i=0;i<listOfPlants.length;i++){
tempQuantityCalc=tempQuantityCalc.replace(listOfPlants[i],1);
}
alert(tempQuantityCalc);
// var numberOccurence= tempQuantityCalc.match(/[\d\.]+/g);
}
</script>
<BODY>
<form name="consumptionBookingForm">
<TABLE cellpadding="0" cellspacing="0" width="50%" height="50%" border="1" bordercolor="#3399FF">
<TR id="cosumptionBookingTag">
<TD>
<select id="myPlantListDropdown" onchange="plantSelectedFromList()">
<option value="Select Plant">Select Plant</option>
<option value="CCRC">CCRC</option>
<option value="CCRP">CCRP</option>
<option value="PHPL">PHPL</option>
<option value="RFMY">RFMY</option>
<option value="SAPL">SAPL</option>
<option value="SMLT">SMLT</option>
<option value="TEOU">TEOU</option>
</select>
</TD>
</TR>
<TR class="ContentHeaderSection">
<TD align="center"><label>Quantity Calculator Formula</label><font color="red">*</font> </TD>
</TR>
<TR>
<TD><textarea cols="90" rows="6" id="myFormulaTextarea"></textarea> </TD>
</TR>
<TR>
<TD align="center"><span class="myButton"><input type="button" id="myValidateCalcButton" onclick="validateQuantityFormula()" value="Validate"></span> </TD>
</TR>
</TABLE>
</form>
</BODY>
</HTML>
Thanks in advance.