wmguk Posted April 11, 2009 Share Posted April 11, 2009 hey, I've just changed some code from <input name="unit1" type="text" id="unit1" style="width: 90px" onChange="calc(1)" /> to <? echo "<input type='text' class='admintext' name='net_$i' value='' onChange=" ."calc(".$i".")" ." style='width: 90px'>"; ?> any idea how I can fix it again? Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/ Share on other sites More sharing options...
steveangelis Posted April 11, 2009 Share Posted April 11, 2009 Try this: echo "<input type='text' class='admintext' name='net_$i' value='' onChange=" .calc("$i") ." style='width: 90px'>"; Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807541 Share on other sites More sharing options...
wmguk Posted April 11, 2009 Author Share Posted April 11, 2009 hmm that fails now, it just removes the input completely.. Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807548 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 You need to escape quotes with a backslash. Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807551 Share on other sites More sharing options...
Mchl Posted April 11, 2009 Share Posted April 11, 2009 More likely: echo "<input type='text' class='admintext' name='net_$i' value=' ' onChange='calc($i)' style='width: 90px' />"; Also: do not use short tags ( <? ). Use full php tag instead ( <?php ) Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807553 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Just out of wonder, does it make any difference..? Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807556 Share on other sites More sharing options...
Mchl Posted April 11, 2009 Share Posted April 11, 2009 You mean short tags? Here are some notes http://www.php.net/manual/en/language.basic-syntax.phpmode.php Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807560 Share on other sites More sharing options...
wmguk Posted April 11, 2009 Author Share Posted April 11, 2009 ok, i tried <?php echo "<input type='text' class='admintext' name='net_$i' value='' onChange=".calc(\"$i")." style='width: 90px'>"; ?> <?php echo "<input type='text' class='admintext' name='net_$i' value='' onChange=".calc(\"$i\")." style='width: 90px'>"; ?> - IT WAS \"$i\" <?php echo "<input type='text' class='admintext' name='net_$i' value='' onChange='calc($i)' style='width: 90px'>"; ?> but none worked Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807562 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Jesus christ <?php echo '<input name="unit1" type="text" id="unit1" style="width: 90px" onChange="calc(\'1\')" />'; ?> Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807580 Share on other sites More sharing options...
wmguk Posted April 11, 2009 Author Share Posted April 11, 2009 thank you for your help, it actually ended up being <?php echo '<input type="text" class="admintext" name="net_'.$i.'" id="qty_'.$i.'" value="" style="width: 90px" onChange="calc(\''.$i.'\')" />'; ?> however for some reason now the javascript still doesnt work... Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807592 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 Well, you'd have to bless us with the pleasure of your javascript if we are to provide the remedy. Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807596 Share on other sites More sharing options...
wmguk Posted April 11, 2009 Author Share Posted April 11, 2009 Sorry, I'm aware that this is the php forum area, not the javascript, so didnt want to appear to take the *** out of anyone... // JavaScript Document var allClients = new Array(); function addClient(name,coname,address,postcode,tel,email){ var curPointer = allClients.length; allClients[curPointer] = new Object(); allClients[curPointer].name = name; allClients[curPointer].coname = coname; allClients[curPointer].address = address; allClients[curPointer].postcode = postcode; allClients[curPointer].tel = tel; allClients[curPointer].email = email; } function findClient(){ var selectedClient = document.getElementById('account_number').value; var clientPos; for(var i=0;i<allClients.length;i++){ if(allClients[i].coname == selectedClient){ clientPos = i; break; } } displayClientInfo(clientPos); } function displayClientInfo(pos){ var target = document.getElementById('net6'); var infoStr = ""; infoStr += "Name: " + allClients[pos].name + "\n"; infoStr += "Company Name: " + allClients[pos].coname + "\n"; infoStr += "Address: " + allClients[pos].address + "\n"; infoStr += "Postal Code: " + allClients[pos].postcode + "\n"; infoStr += "Telephone: " + allClients[pos].tel + "\n"; infoStr += "Email: " + allClients[pos].email; target.value = infoStr; } function calc(which){ if(document.getElementById("qty" + which).value && document.getElementById("unit" + which).value){ var qty = document.getElementById("qty" + which).value; var uPrice = document.getElementById("unit" + which).value; var netPrice = qty * uPrice; netPrice = netPrice.toFixed(2); document.getElementById("net" + which).value = netPrice; calcTotal(); } } function calcTotal(){ var depositAmount = 0; var subTotal = 0; var netPrices = new Array();; netPrices[0] = document.getElementById("net_1").value; netPrices[1] = document.getElementById("net_2").value; netPrices[2] = document.getElementById("net_3").value; netPrices[3] = document.getElementById("net_4").value; netPrices[4] = document.getElementById("net_5").value; for(var i=0;i<netPrices.length;i++){ if(netPrices[i]){ subTotal += parseFloat(netPrices[i]); } } subTotal = subTotal.toFixed(2); var VAT = subTotal * 0.15; VAT = VAT.toFixed(2); var InTotal = parseFloat(subTotal) + parseFloat(VAT); var InTotal = InTotal.toFixed(2) depositAmount = document.getElementById("deposit").value; var balanceDue = InTotal - depositAmount; balanceDue = balanceDue.toFixed(2); document.getElementById("total_net").value = subTotal; document.getElementById("total_vat").value = VAT; document.getElementById("total").value = InTotal; document.getElementById("balance").value = balanceDue; } and the code which generates it is now <?PHP for($i = 1;$i <= $count;$i++) { ?> <tr> <td align="center"><?php echo '<input type="text" class="admintext" name="qty_'.$i.'" id="qty_'.$i.'" value="" style="width: 50px" onChange="calc(\''.$i.'\')" />'; ?></td> <td align="center"><?php echo '<input type="text" class="admintext" name="details_'.$i.'" id="qty_'.$i.'" value="" style="width: 560px" onChange="calc(\''.$i.'\')" />'; ?></td> <td align="center"><?php echo '<input type="text" class="admintext" name="unit_'.$i.'" id="qty_'.$i.'" value="" style="width: 90px" onChange="calc(\''.$i.'\')" />'; ?></td> <td align="center"><?php echo '<input type="text" class="admintext" name="net_'.$i.'" id="qty_'.$i.'" value="" style="width: 90px" onChange="calc(\''.$i.'\')" />'; ?></td> </tr> <? } ?> Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807599 Share on other sites More sharing options...
bloodgoat Posted April 11, 2009 Share Posted April 11, 2009 <?php echo "<input name=\"unit1\" type=\"text\" id=\"unit1\" style=\"width: 90px\" onChange=\"calc(".$i.")\">"; ?> Eh? Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807601 Share on other sites More sharing options...
jackpf Posted April 11, 2009 Share Posted April 11, 2009 What javascript error are you getting? Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807602 Share on other sites More sharing options...
redarrow Posted April 11, 2009 Share Posted April 11, 2009 DID U READ THIS PAL? Also: do not use short tags ( <? ). Use full php tag instead ( <?php ) Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807603 Share on other sites More sharing options...
wmguk Posted April 11, 2009 Author Share Posted April 11, 2009 DID U READ THIS PAL? Also: do not use short tags ( <? ). Use full php tag instead ( <?php ) yes i did, wow im sorry, i missed one set of tags!!!! chill out!!!! Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807607 Share on other sites More sharing options...
wmguk Posted April 11, 2009 Author Share Posted April 11, 2009 What javascript error are you getting? its "object required" line 42, char 2 Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807609 Share on other sites More sharing options...
wmguk Posted April 11, 2009 Author Share Posted April 11, 2009 ahhh!! ok, so i changed it and now its working, except the subtotal / total vat area isnt working... function calc(which){ if(document.getElementById("qty_" + which).value && document.getElementById("unit_" + which).value){ var qty = document.getElementById("qty_" + which).value; var uPrice = document.getElementById("unit_" + which).value; var netPrice = qty * uPrice; netPrice = netPrice.toFixed(2); document.getElementById("net_" + which).value = netPrice; calcTotal(); } } now works ^^ but function calcTotal(){ var depositAmount = 0; var subTotal = 0; var netPrices = new Array();; netPrices[0] = document.getElementById("net_1").value; netPrices[1] = document.getElementById("net_2").value; netPrices[2] = document.getElementById("net_3").value; netPrices[3] = document.getElementById("net_4").value; netPrices[4] = document.getElementById("net_5").value; for(var i=0;i<netPrices.length;i++){ if(netPrices[i]){ subTotal += parseFloat(netPrices[i]); } } subTotal = subTotal.toFixed(2); var VAT = subTotal * 0.15; VAT = VAT.toFixed(2); var InTotal = parseFloat(subTotal) + parseFloat(VAT); var InTotal = InTotal.toFixed(2) depositAmount = document.getElementById("deposit").value; var balanceDue = InTotal - depositAmount; balanceDue = balanceDue.toFixed(2); document.getElementById("total_net").value = subTotal; document.getElementById("total_vat").value = VAT; document.getElementById("total").value = InTotal; document.getElementById("balance").value = balanceDue; doesnt seem to work - it should auto calculate however its not doing it Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807615 Share on other sites More sharing options...
wmguk Posted April 12, 2009 Author Share Posted April 12, 2009 does anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/153671-broke-my-javascript-making-it-php/#findComment-807760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.