Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP, MYSQL select box not selecting correctly

Tags:

javascript

php

Got another wierd 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 the example I'm running $row['pNum'] = 6 and I'm selecting select value 31. When I do alert on params in the js sWield = 0 and sNum = 6. The thing is, sWield should be 31. Ideas?. If I run with different values, say $row['pNum'] = 11 and select value 25 in the js sWield = 25 and sNum is 11 the way it should be. Ideas?

like image 274
S.e. Estes Avatar asked Feb 18 '26 22:02

S.e. Estes


1 Answers

You are not closing the first option echo "<option value=0>Use On</option>";

Try closing this one first!

like image 60
SativaNL Avatar answered Feb 21 '26 12:02

SativaNL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!