Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][AJAX]Funkcja nie może wyciągnąć wartości elementu
kacpero1094
post
Post #1





Grupa: Zarejestrowani
Postów: 87
Pomógł: 0
Dołączył: 22.12.2008

Ostrzeżenie: (0%)
-----


Mam kod:
  1. function getXMLHttpRequest() {
  2. var request = false;
  3. try {
  4. request = new XMLHttpRequest();
  5. } catch(err1) {
  6. try {
  7. request = new ActiveXObject('Msxml2.XMLHTTP');
  8. } catch(err2) {
  9. try {
  10. request = new ActiveXObject('Microsoft.XMLHTTP');
  11. } catch(err3) {
  12. request = false;
  13. }
  14. }
  15. }
  16. return request;
  17. }
  18. var p=new getXMLHttpRequest();
  19. function processResponse(id)
  20. {
  21. if (p.readyState == 4) {
  22. if (p.status == 200) {
  23. var div='question-' + id;
  24. document.getElementById(div).style.display='block';
  25. document.getElementById(div).innerHTML=p.responseText;
  26. };
  27. };
  28. }
  29. function sendAnswer(id) {
  30. var name='question-' + id;
  31. var form=document.getElementById(name);
  32. var ans='questionAns-' + id;
  33. var answer=form.ans.value;
  34. p.open('GET','sendAnswer.php?id=' + id + '&ans=' + answer,true);
  35. p.onreadystatechange = processResponse(id);
  36. p.send(null);
  37. }

Plik senAnswer.php jest na 100% sprawny. Wiem, że to wina JS, tylko nie potrafię znaleźć błędu.

Dodam jeszcze fragment, w którym są formularze.
  1. while ($row=mysql_fetch_array($query)) {
  2. echo '<div id="question-' . $row['id'] . '">
  3. <table border="0">
  4. <tr>
  5. <td style="width: 400px;">Pytanie: <b>' . $row['question'] . '</b></td>
  6. <td><input checked="checked" type="radio" name="questionAns-' . $row['id'] . '" value="0"> <label>Nie</label> <input type="radio" name="questionAns-' . $row['id'] . '" value="1"> <label>Tak</label> <input type="radio" name="questionAns-' . $row['id'] . '" value="0"> <label>Nie wiem</label></td>
  7. <td><input type="button" value="Wyślij >>" onclick="sendAnswer(' . $row['id'] . ')" /></td>
  8. </tr>
  9. </table>
  10. </div>';
  11. }

Z góry dziękuję za pomoc.


--------------------
kacperkolodziej.pl
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 14:10