3

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?

6
  • 1
    Please show the resulting HTML that is rendered by PHP. Commented Apr 16, 2012 at 18:00
  • do the weird results you get match up with the database? Commented Apr 16, 2012 at 18:01
  • 1
    Is the HTML output from your PHP code assigning values correctly in the <select> element? Seems to me that the value= of $row['pNum'] = 6 is not being passed to the wieldit() function Commented Apr 16, 2012 at 18:03
  • The results match up with the database. I don't know how to show the resulting html. I'm using ajax and the only html the shows rendered is my index page with the standard divs I set up. It's the sWield being 0 that's the problem. Commented Apr 16, 2012 at 18:06
  • Ok, I could view the rendered html and it looks fine. I'd send it in the comment but it won't let me so it can be seen at this link: link Commented Apr 16, 2012 at 18:27

2 Answers 2

3

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

Try closing this one first!

Sign up to request clarification or add additional context in comments.

1 Comment

most browsers can deal with that no problem (same with <li>), always best to close though.
0

Value 31 is the 7th option in your selectbox. As Javascript starts counting from 0, it's displaying 6.

So it seems it alerts the index in stead of the chosen value. You could try to try this, and put quotes around the value: <option value='31'>Arms</option>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.