"; echo "".$r...">

PHP, MYSQL select box not selected correctly

Got another simpler one:

Here is my php:

echo "</tr><tr>";
echo "<td style='color:white;'>".$row['iDesc']."</td><td>".$row['pCnt']."</td><td style='color:".$color.";'>".$row['pDur']."</td><td>".$row['pStr']."</td><td>".$row['pSpd']."</td><td>";
echo "<select name='wield".$row['pNum']."' id='wield".$row['pNum']."' size='1' style='width: 100px;' onChange='wieldit(".$row['pNum'].");'>";
echo "<option value=0>Use On";
$query = "Select item, iDesc from item where iType = 1";
$result2 = mysql_query($query, $_SESSION['connect']);
while ($row2 = mysql_fetch_array($result2)) {
  echo "<option";
  echo " value=".$row2['item'].">".$row2['iDesc']."</option>";
}
echo "</select></td>";
}

Here is my js:

function wieldit(num) {
    var id = "wield"+num;
    var e = $(id); 
    var t =  e.options[e.selectedIndex].value;
    var params = "sWield="+t;
    params += "&sNum="+num;
    new Ajax.Updater('div06', 'php/pack.php', {method: 'get', parameters: params, onComplete: showBody});
}

When I run it, the values ​​in the select box are 0, 1, 2, 26, 25, 24, 23, 31. For example, I run $ row ['pNum'] = 6, and I select the value of choice 31. When I warn about the parameters in js sWield = 0 and sNum = 6. The fact is that sWield should be 31. Ideas ?. If I run different values, say $ row ['pNum'] = 11 and select the value 25 in js sWield = 25, and sNum - 11, as it should be. Ideas?

+3
source share
2 answers

The value 31 is the 7th option in your selectbox. When Javascript starts counting from 0, it displays 6.

, , . : <option value='31'>Arms</option>

0

echo "<option value=0>Use On</option>";

!

+3

All Articles