Jump to content

Problem HTML/Javascript


Recommended Posts

  • Management

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

BiDcfPn.png

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 by Metin2 Dev
Core X - External 2 Internal

raw

raw

Link to comment
Share on other sites

  • Premium

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

  • Love 1
Link to comment
Share on other sites

  • Management

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

raw

raw

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.