duanfang2708 2013-05-10 11:30
浏览 27
已采纳

如何通过javascript正确选择(或不)正确选择值?

I'm trying to add a value from a radio button form into my DB but my javascript doesn't return any errors and it's not working. I think my selector might not be working but how do I check that ? What's wrong with my function ?

JS

<script type="text/javascript" >
    function addScore() {
    $("#submitscore").click(function() 
    {
    var show_id = $('#show_id').val();  
    var user_id = $('#user_id').val();
    var score = $('input[name=tvshowrating]:checked').val();
    if(score=='')
    {
    alert('PleaseEnter A Score');
    }
    else
    {
    $("#flash").show();
    $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Score...');
    $.ajax({
    type: "POST",
    url: "showscoreajax.php",
            data:{
            "show_id" : show_id,  
            "user_id" : user_id,
            "score" : score          //we are passing the name value in URL
            },
    cache: false,
    success: function(html){
    $("#flash").html('Added');
    }
    });
    }return false;
    }); 
    };


    </script>

HTML

<form id="form3B">


    <div class="your-score">
        <div class="">Your Score</div>
        <div id="flash"></div>
         <input class="hover-star" type="radio" name="tvshowrating" value="1" title="1"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="2" title="2"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="3" title="3"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="4" title="4"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="5" title="5"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="6" title="6"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="7" title="7"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="8" title="8"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="9" title="9"/>
         <input class="hover-star" type="radio" name="tvshowrating" value="10" title="10"/>    
         <input type="hidden" id="show_id" value="<?php echo $row[0]; ?>" /> 
         <input type="hidden" id="user_id" value="<?php echo $user_id ?>" />
         <span id="hover-test" style="margin:0 0 0 20px;"></span>
    </div>
    </div></div>
       <input id="submitscore" type="submit" value="Submit scores!" onclick="addScore()" />  
       <u>Test results</u>:<br/><br/>
       <div class="test Smaller">
        <span style="color:#FF0000">Results will be displayed here</span>
       </div>

    </form> 
  • 写回答

3条回答 默认 最新

  • douxin1956 2013-05-10 11:33
    关注

    There is no need to use $("#submitscore").click(function() in the addSote() method since it called on click on the button

    function addScore() {
        var show_id = $('#show_id').val();  
        var user_id = $('#user_id').val();
        var score = $('input[name=tvshowrating]:checked').val();
        if(!score)
        {
            alert('PleaseEnter A Score');
        }
        else
        {
            $("#flash").show();
            $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Score...');
            $.ajax({
                type: "POST",
                url: "showscoreajax.php",
                data:{
                    "show_id" : show_id,  
                    "user_id" : user_id,
                    "score" : score          //we are passing the name value in URL
                },
                cache: false,
                success: function(html){
                    $("#flash").html('Added');
                }
            });
        }
        return false;
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)