选择后运行提交表单

时间:2011-05-29 10:55:50

标签: jquery forms submit

我遇到一个小问题,我正在尝试运行$("form#picform").submit

此功能后

$('select[name="phototype"]').live('change',function(){

if (this.value) {
            $(this).closest('form').submit();
    }
});

我需要运行此功能

$("form#pendingpic").submit(function(){
    alert($('#picid').val());
    return false;
});

这是我的完整js文件。

    var session = null;
var sessionparts = null;





$(document).ready(function(){


    window.scrollTo(0, 1);


    $('select[name="phototype"]').live('change',function(){
    var $el = $(this);

    if ($el.val()) {
        $el.closest('form').submit();
    }   

      $("form#pendingpic").trigger('submit');
    });

    if ($.cookies.get('_Squirtnow_AdminSession') != null) {
           session = $.cookies.get('_Squirtnow_AdminSession');
           successlogin();
        }


    $('ul#mainmenu a li').live('click', function(event){
            //alert(this.id);

            $("li#"+lastpageid).removeClass();
            fetchpage(this.id);


            var text = '';
            $('a li#'+this.id+'').contents().each(function(){
            if(this.nodeType === 3){
             text += this.wholeText;
            }
            });

            $("#largemenutop").html(text);

            $("li#"+this.id).addClass("active");
            lastpageid = this.id;
    });



    });

//form code
$(function() {   

    $("form#pendingpic").submit(function(){
        //alert($('#picid').val());

        $.ajax({
            type: "POST",
            url: "goog.php",
            data: "process=1&username="+ username +"&password="+ password,
            success: function(data){
            if((data) == 1)
            {
                $('#notify').fadeOut(10);
                session = $.cookies.get('_Squirtnow_AdminSession');
                successlogin();
            }
            else
            {
                $('#notify').show();
                $('#notifytext').html(data);
                setTimeout(function() {
                $('#notify').fadeOut(1000);
                }, 4000);
                }
            }

        });

        return false;
    });

    $("form#login").submit(function() {

        var username    = $('#username').attr('value');
        var password    = SHA1($('#password').attr('value'));


        $('#notify').show();
                $('#notifytext').html("Please wait...<br/>We are processing your login form.");

        $.ajax({
            type: "POST",
            url: "sys/classes/userlogin.php",
            data: "process=1&username="+ username +"&password="+ password,
            success: function(data){
            if((data) == 1)
            {
                $('#notify').fadeOut(10);
                session = $.cookies.get('_Squirtnow_AdminSession');
                successlogin();
            }
            else
            {
                $('#notify').show();
                $('#notifytext').html(data);
                setTimeout(function() {
                $('#notify').fadeOut(1000);
                }, 4000);
                }
            }

        });
    return false;





    });

    //end of code
});


function successlogin(){
    sessionparts = session.split('|');
    changelayout();
    fetchmenus();
//  basicinfomenu();
//  checkuserprofile();
    fetchpage("home");
}



function fetchmenus(){

    $("<a href='#/page/home'><li id='home'><img src='theme/images/space.png' id='menu' class='home'/><br/>Home</li></a>").appendTo("ul#left");
    $("<a href='#/page/pendingusers'><li id='pendingusers'><img src='theme/images/space.png' id='menu' class='pendingusers'/><br/>Pending Users</li></a>").appendTo("ul#left");
    $("<a href='#/page/pendingpictures'><li id='pendingpictures'><img src='theme/images/space.png' id='menu' class='pendingpictures'/><br/>Pending Pictures</li></a>").appendTo("ul#left");

    $("<a href='#/page/sendmail'><li id='sendmail'><img src='theme/images/space.png' id='menu' class='sendmail'/><br/>Send Mail</li></a>").appendTo("ul#right");
    $("<a href='#/page/users'><li id='users'><img src='theme/images/space.png' id='menu' class='users'/><br/>Users</li></a>").appendTo("ul#right");
    $("<a href='#/page/stats'><li id='stats'><img src='theme/images/space.png' id='menu' class='stats'/><br/>Stats</li></a>").appendTo("ul#right");


}



function changelayout(){
    $("#successloginfull").html("<ul id='left'></ul>   <ul id='right'></ul>   <div id='mainarea'><div id='mainmenuheader'></div><div id='htmlarea'></div></div>");  

$("#onehundredpercent").hide();
$("#successloginfull").show();
}





function fetchpage(e){

        if(e == "home")
        {
            $("<div id='pendpicarea' class='threeten'></div><div id='trackingarea' class='threeten'></div><div id='sysmessagearea' class='threeten'></div>").appendTo("#htmlarea");

            homependingpics();
            hometrackusers();

        }

}


function homependingpics(){
    $.getJSON('sys/classes/fetch.php?fetch=pendingpic',function(fetchpendingpics){
                            // get line status

        $.each(fetchpendingpics, function(i,item){
            $("<div id='box'><img src='../sys/classes/fetchpicture.php?pic="+item.id+":917715617567156645'><form method='post' id='pendingpic' name='pendingpic'><input name='picid' type='hidden' id='picid' value='"+item.id+"'/><select name='phototype' id='phototype'><option value='' disabled>Rate Pic</option><option value='1'>G Rated</option><option value='2'>X Rated</option></select></form></div>").appendTo("#pendpicarea");    
        })

    })  
}

function hometrackusers(){
    setTimeout(function(){
        $.getJSON('sys/classes/fetch.php?fetch=trackusers',function(fetchpendingpics){
                            // get line status

            $.each(fetchpendingpics, function(i,item){
                $("").appendTo("#trackingarea");
            })

        })
    },1000);
}

1 个答案:

答案 0 :(得分:1)

$('select[name="phototype"]').live('change',function(){
  var $el = $(this);

  if ($el.val()) {
    $el.closest('form').submit();
  }

  $("form#pendingpic").trigger('submit');
});