Probleme mit JS-Rating-Script

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Probleme mit JS-Rating-Script

    Hallo,

    ich habe das Rating-Script des WBB ein wenig umgeschrieben und nun wird das Rating nicht mehr abgesendet, wenn man als User klickt. Alles andere funktioniert wie gewollt:

    Quellcode

    1. function Rating(elementName, currentRatingnNow, userCanRateNow) {
    2. this.elementName = elementName;
    3. this.currentRating = currentRatingnNow;
    4. var userCanRate = userCanRateNow;
    5. /**
    6. * Initialises a new rating option.
    7. */
    8. this.init = function() {
    9. var span = document.getElementById(this.elementName + 'Span');
    10. if (span) {
    11. // add stars
    12. for (var i = 1; i <= 5; i++) {
    13. var star = document.createElement('img');
    14. star.src = RELATIVE_WBB_DIR+'icon/noRatingS.png';
    15. star.alt = '';
    16. star.rating = this;
    17. star.name = i;
    18. if(userCanRate == 1) {
    19. star.onmouseover = function() { this.style.cursor = 'pointer'; this.rating.showRating(parseInt(this.name)); };
    20. star.onclick = function() { this.rating.submitRating(parseInt(this.name)); };
    21. }
    22. span.appendChild(star);
    23. }
    24. // add listener
    25. span.rating = this;
    26. span.onmouseout = function() { this.rating.showCurrentRating(); };
    27. // set visible
    28. span.className = '';
    29. }
    30. if (this.currentRating > 0) {
    31. this.showCurrentRating();
    32. }
    33. }
    34. /**
    35. * Shows the current user rating.
    36. */
    37. this.showCurrentRating = function() {
    38. this.showRating(this.currentRating);
    39. }
    40. /**
    41. * Shows a selected rating.
    42. */
    43. this.showRating = function(rating) {
    44. var span = document.getElementById(this.elementName + 'Span');
    45. if (span) {
    46. for (var i = 1; i <= rating; i++) {
    47. if (span.childNodes[i - 1]) {
    48. span.childNodes[i - 1].src = RELATIVE_WBB_DIR+'icon/ratingS.png';
    49. }
    50. }
    51. for (var i = rating + 1; i <= 5; i++) {
    52. if (span.childNodes[i - 1]) {
    53. span.childNodes[i - 1].src = RELATIVE_WBB_DIR+'icon/noRatingS.png';
    54. }
    55. }
    56. }
    57. }
    58. /**
    59. * Submits a selected rating.
    60. */
    61. this.submitRating = function(rating) {
    62. var element = document.getElementById(elementName);
    63. var select = document.getElementById(elementName + 'Select');
    64. if (element) {
    65. this.currentRating = rating;
    66. element.value = rating;
    67. if (select) {
    68. select.selectedIndex = rating - 1;
    69. }
    70. element.form.submit();
    71. }
    72. }
    73. this.init();
    74. }
    Alles anzeigen


    Quellcode

    1. <script type="text/javascript" src="{@RELATIVE_WBB_DIR}js/gxRating.class.js"></script>
    2. <form method="post" action="index.php?form=RatingSystem">
    3. <div>
    4. <input type="hidden" name="ratingID" value="1" />
    5. <input type="hidden" name="ratingKonstante" value="Beispiel" />
    6. <input type="hidden" name="submit" value="true" />
    7. {@SID_INPUT_TAG}
    8. <input type="hidden" id="BeispielRating" name="rating" value="0" />
    9. <span class="hidden" id="BeispielRatingSpan"></span>
    10. </div>
    11. </form>
    12. <script type="text/javascript">
    13. //<![CDATA[
    14. new Rating('BeispielRating', 2, 1);
    15. //]]>
    16. </script>
    Alles anzeigen
  • Kein Problem ;)


    Zeile 19 bis 22:


    JETZT

    Quellcode

    1. if(userCanRate == 1) {
    2. star.onmouseover = function() { this.style.cursor = 'pointer'; this.rating.showRating(parseInt(this.name)); };
    3. star.onclick = function() { this.rating.submitRating(parseInt(this.name)); };
    4. }



    VORHER

    Quellcode

    1. star.onmouseover = function() { this.style.cursor = 'pointer'; this.rating.showRating(parseInt(this.name)); };
    2. star.onclick = function() { this.rating.submitRating(parseInt(this.name)); };
  • Bist du dir sicher, dass UserCanRate(Now) auf 1 gesetzt ist? vielleicht ist es ein boolean wert. Du solltest im dir im Scriptteil UserCanRate(Now) ausgeben lassen.
    Von der Syntax her ist alles richitg. Ich bin mir sicher, dass es an der Variable liegt.
    Open Source --> Programmieren aus Leidenschaft :!:

    Ich stehe weder für privaten Support per PM noch über einen IM zur Verfügung. Danke.