16. august 2001 - 14:19Der er
6 kommentarer og 1 løsning
Help with a form function
Hi There
I am trying to get my form to calculate a price for me in my db the prices are in DK ie: 56,50 The form can calculate the price if it is a whole number like 43,00 <-- however when the price is like this 43,50 then the price does not get calculated ?
heres some of the code I use to work out the price I dont know if this is an ASP error or javascript
<script language=\"JavaScript\"> function Wine(Pris) { string = \"\" + Pris; number = string.length - string.indexOf(\',\'); if (string.indexOf(\',\') == -1) return string + \',00\'; if (number == 1) return string + \'00\'; if (number == 2) return string + \'0\'; if (number > 3) return string.substring(0,string.length-number+3); return string; }
function calculate() { document.multi.result1.value = Wine((document.multi.Artikel1.value)*(document.multi.Antal1.value)) }
Are you sure that your returned value of ((document.multi.Artikel1.value)*(document.multi.Antal1.value)) is a NaN or Not if any comma exists, try using . as comma instead. And when you converts to string, then look for the . instead of ,
I cant really work it out heres the javascript again :=) <script language=\"JavaScript\"> function Wine(Pris) { string = \"\" + Pris; number = string.length - string.indexOf(\',\'); if (string.indexOf(\'.\') == -1) return string + \',00\'; if (number == 1) return string + \'00\'; if (number == 2) return string + \'0\'; if (number > 3) return string.substring(0,string.length-number+3); return string; }
function calculate() { document.multi.result1.value = Wine((document.multi.Artikel1.value)*(document.multi.Antal1.value)) } </script>
and here are the 3 areas from the form the first is the price from my db <input type=\"hidden\" value=\"<%=wine_info(\"Pris\")%>\" name=\"Artikel1\" size=\"1\" onChange=\"calculate()\"> the next is how many time it gets calculated <SELECT ID=FORM name=\"Antal1\" size=\"1\" onChange=\"calculate()\">
And heres where the value get inserted <INPUT type=text name=\"result1\" size=\"8\" value=\"0.00\" onfocus=this.blur() >
When I do choose a value like 45,50 then it gets displayed as NaN,00 you named it before(NaN) <-- but I dont know what NaN is :( Any ideas Guzzie
NaN - not a number It cannot time 45,50 with the number of items, for instance 3*45,50 => is not a number, however 45.50*3 => is a number! I\'m not sure whether regional settings can solve this problem, otherwise use a (.) instead of (,)
how would I go about replacing at runtime ? or do you have a link to where there r examples ? I think this would be a good idea as the database is already set up to accept DK Guzzie
this works great <% FUNCTION fixComma( thisString ) fixComma = Replace( thisString, \",\", \".\" ) END FUNCTION %>
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.