GeRik Posted October 5, 2010 Report Share Posted October 5, 2010 Lūk šim JavaScript vaidzētu automātiski aprēķināt Cenas ar PVN <script> function DoMath(){ var PVN = document.mats.PVN[i].value var aCOUNT = document.mats.PVN[i].value * document.mats.count[i].value var bPVN = parseInt(aCOUNT) * 1.21 document.mats.bPVN[i].value = bPVN } </script> Un lūk HTML daļa bet nekas nestrāda ja piemēram noņemu un Html daļā [1] Tad viss strādā varbūt varat palīdzēt visu savest kārtība vai vismaz paskaidrot kas un kā. <tr> <th scope="row">1</th> <td><input id='1' name='mat[1]' value='Materiāls' type='text'></td> <td><input id='1' name='count[1]' value='Skaits' type='text' onchange="DoMath()"></td> <td><input id='1' name='PVN[1]' value='0.00' type='text' onchange="DoMath()"></td> <td><input id='1' name='bPVN[1]' value='0.00' type='text'></td> </tr> <tr> <th scope="row">1</th> <td><input id='1' name='mat[2]' value='Materiāls' type='text'></td> <td><input id='1' name='count[2]' value='Skaits' type='text' onchange="DoMath()"></td> <td><input id='1' name='PVN[2]' value='0.00' type='text' onchange="DoMath()"></td> <td><input id='1' name='bPVN[2]' value='0.00' type='text'></td> </tr> Quote Link to comment Share on other sites More sharing options...
briedis Posted October 5, 2010 Report Share Posted October 5, 2010 A kur tev tur rodas tāds "i" mainīgais? Quote Link to comment Share on other sites More sharing options...
GeRik Posted October 5, 2010 Author Report Share Posted October 5, 2010 (edited) A kur tev tur rodas tāds "i" mainīgais? Nu nerodas bet man vaig lai JS saprast ka tur ir array un lai viņš to dara ar visiem, jo piemēram kad es noņemu no JS tos tad viss strādā (tikai pirmajam ja protams pirmajam noņem [1]). Tapēc cenšos izštukot kā lai viņš to veic ar visiem pēc kārtas Edited October 5, 2010 by GeRik Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted October 5, 2010 Report Share Posted October 5, 2010 Padod funkcijai kā parametru to i. Jā un iekš html id nevajadzētu būt vienādiem. Quote Link to comment Share on other sites More sharing options...
GeRik Posted October 5, 2010 Author Report Share Posted October 5, 2010 (edited) Padod funkcijai kā parametru to i. Jā un iekš html id nevajadzētu būt vienādiem. Jā tie id nav vienādi vienkārši te es kopēju. Bet tieši jautājums kā funkcijai viņu padot kā parametru lai viņš uz visiem strādā gan uz mat[1] mat[2] mat[3] EDIT: mēģināju šādi arī nekas nesanāk :( <script> function DoMath(){ var counter = 1; var limit = 20; if (counter == limit) { alert("Sasniegts Matriealu Limits " + counter + ""); } var PVN = document.mats.PVN[(counter + 1)].value var aCOUNT = document.mats.PVN[(counter + 1)].value * document.mats.count[(counter + 1)].value var bPVN = parseInt(aCOUNT) * 1.21 document.mats.bPVN[(counter + 1)].value = bPVN counter++; } </script> Edited October 5, 2010 by GeRik Quote Link to comment Share on other sites More sharing options...
briedis Posted October 5, 2010 Report Share Posted October 5, 2010 Id nedrīkst būt skaitlis! liec id - "item-10", piemēram un onchange="doStuff(10);" un function doStuff(id){ elem = document.getElementById("item-" + id) ... } Quote Link to comment Share on other sites More sharing options...
GeRik Posted October 5, 2010 Author Report Share Posted October 5, 2010 Id nedrīkst būt skaitlis! liec id - "item-10", piemēram un onchange="doStuff(10);" un function doStuff(id){ elem = document.getElementById("item-" + id) ... } Bet man tak to nevaig uz id bet uz name ja piemēram name ir kaka man vaig lai vinjam butu kaka[1] jo pectam man tas viss jaliek datubāzē piemēram foreach ($field as $value) { mysql_query("bla bla bla") } Quote Link to comment Share on other sites More sharing options...
sheps Posted October 5, 2010 Report Share Posted October 5, 2010 man liekas tu pats kko putro :D <script> function DoMath(i){ var PVN = document.getElementsByName('PVN['+i+']')[0].value; var aCOUNT = PVN * document.getElementsByName('count['+i+']')[0].value; var bPVN = parseInt(aCOUNT) * 1.21; document.getElementsByName('bPVN['+i+']')[0].value = bPVN; } </script> <input name="count[1]" value="0" type="text" onchange="DoMath(1)"> <input name="PVN[1]" value="0" type="text" onchange="DoMath(1)"> <input name="bPVN[1]" value="0" type="text"> luukt tev bez ID :) šis tok strādās.. ja jau skaits un cena ir mainiigie lielumi, gala cenas lauku nevajadzeetu ka input (lai nevar editēt) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.