Management Karbust 4884 Posted March 27, 2016 Management Share Posted March 27, 2016 (edited) Hello, I trying to create a system that gives the options to the player to buy on item shop for him self or other player. This is my code: Spoiler <table> <?PHP $sqlQry=mysql_query($sqlCmdS,$sqlHp); while($getItems=mysql_fetch_object($sqlQry)) { $aktItem = compareItems($getItems->vnum); $aktItem1 = compareItems($getItems->id); $nome = compareItems($getItems->nome); $itemStufe = (checkInt($aktItem['stufe'])) ? "+".$aktItem['stufe'] : ''; //$itemStufe1 = (checkInt($aktItem1['stufe'])) ? "+".$aktItem1['stufe'] : ''; ?> <tr> <th colspan="2" class="topLine"><?PHP echo $nome['item']; ?> (<b><?PHP echo $getItems->count; ?>x</b>) (<b><?PHP echo $getItems->preis; ?> Coins</b>)</th> </tr> <tr> <td class="isImg"> <?PHP if(!empty($getItems->bild)) echo'<img src="./is_img/'.$getItems->bild.'.png" title="'.$aktItem['item'].'" alt="'.$aktItem['item'].'"/>'; ?> </td> <td class="tdunkel"><?PHP echo $getItems->beschreibung; ?></td> </tr> <tr> <td colspan="2" class="isBuy"> <select id ="escolha"> <option value="">Escolhe...</option> <option value="eu">Para mim</option> <option value="outro">Para outro jogador</option> </select><button onclick="confirmacao(escolha,<?PHP echo $getItems->id; ?>,<?PHP echo $getItems->preis; ?>)" title="Vais gastar <?PHP echo $getItems->preis; ?> moedas">Comprar</button></td> </tr> <?PHP } ?> </table> </div> <script> function confirmacao(escolhida,id,preco) { //var val = escolhida.options[escolhida.selectedIndex].value; switch(escolhida.options[escolhida.selectedIndex].value) { case "eu": function confirma_compra(id,preco) { var ask = window.confirm("Queres mesmo comprar?\nIram ser removidas "+preco+" moedas da tua conta!"); if (ask) { document.location.href = './is_buy-'+id+'.htm'; } } return confirma_compra(id,preco) break; case "outro": document.location.href = './is_buy_outro-'+id+'.htm'; break; case "": alert("Tens de selecionar uma opção!"); break; default: alert("test"); } return false; } </script> But there is a problem, just the first item's select box is valid to all the itens If I select the first option on the first item I just can use that option for all the itens, the option select on the other item is ignored... Someone can help me? I don't now what I doing wrong... Thanks Kind regards, charparodar Edited August 20, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Management Karbust 4884 Posted March 28, 2016 Author Management Share Posted March 28, 2016 Bring Up My Post Link to comment Share on other sites More sharing options...
Management Karbust 4884 Posted March 29, 2016 Author Management Share Posted March 29, 2016 Bring Up My Post Link to comment Share on other sites More sharing options...
Management Karbust 4884 Posted March 30, 2016 Author Management Share Posted March 30, 2016 Someone please... Link to comment Share on other sites More sharing options...
Premium Istny 79 Posted March 30, 2016 Premium Share Posted March 30, 2016 in the future past code in english not mixed with portuguese ;p in while loop you are displaying button with onclick function but the first argument i guess have to be unical and it's not so you ALWAYS pass to javascript function "confirmacao(escolhida,id,preco)" the same first argument i have added counter, so now every html select have unique id which is passing to javascript function http://pastebin.com/hKKjdPbW 1 Link to comment Share on other sites More sharing options...
Management Karbust 4884 Posted March 30, 2016 Author Management Share Posted March 30, 2016 I have this error: Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\habiramt2\pages\itemshop.php on line 56 Line 56: </select><button onclick="confirmacao(escolha<? $counter ?>,<?= $getItems->id ?>,<?= $getItems->preis; ?>)" title="Vais gastar <?= echo $getItems->preis; ?> moedas">Comprar</button> I noticed that the function is not receiving the counter argument, I don't now much of java, so how can I read that? Thanks Link to comment Share on other sites More sharing options...
Premium Istny 79 Posted March 30, 2016 Premium Share Posted March 30, 2016 http://pastebin.com/tFuHP6WY i forget about one "=" sign check now 1 Link to comment Share on other sites More sharing options...
Management Karbust 4884 Posted March 30, 2016 Author Management Share Posted March 30, 2016 It's already working, but I had to move the $counter = 1 to outsite the loop, otherwise it would be always setting to one... Link to comment Share on other sites More sharing options...
Premium Istny 79 Posted March 30, 2016 Premium Share Posted March 30, 2016 1 minute ago, charparodar said: It's already working, but I had to move the $counter = 1 to outsite the loop, otherwise it would be always setting to one... looks like is something wrong with me today xD Link to comment Share on other sites More sharing options...
Management Karbust 4884 Posted March 30, 2016 Author Management Share Posted March 30, 2016 Everyone can do something wrong, yet you helped me a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now