English 中文(简体)
需帮助将变量转换成美元(原始)。 页: 1
原标题:need help passing variables into $(#something).submit(function(e){
  • 时间:2012-01-13 15:27:07
  •  标签:
  • jquery
  • forms

I m new to jQuery and am having a couple problems with this code:

var theCommentId =   ;
var buildFormName =   ;

$( .comment_submit ).bind( click , function() {
    theCommentId = $(this).attr( this_id );
    buildFormName = ( #AddMessageForm_  + theCommentId);
}); 

alert(buildFormName);

This returns #AddMessageForm_1 (or 2 or 234 depending on what button is clicked). That part is working great.

But then I need to pass buildFormName in here so I can process multiple forms with different names. The form names are generated dynamically from an id number that s appended to addMessageForm

$(buildFormName).submit(function(e) {
    // process form data here...
    $.post( process.php , $(this).serialize(), function(msg) {
    }

The above returns no errors, but $this is empty and I can t create the db row from an empty $this! it works if I don t try to pass the variable buildFormName in there. example:

$( #addMessageForm_1 ).submit(function(e) {
    // process form data here...
    $.post( process.php ,$(this).serialize(),function(msg){
    }

罚款。 我希望,我在这里没有简单的东西。 任何帮助都受到高度赞赏。

感谢!

问题回答

您应将提交书记员作为单独的职能,然后使用。 引证。

$( .comment_submit ).bind( click ,function(){
    theCommentId = $(this).attr( this_id );

    buildFormName = ( #AddMessageForm_  + theCommentId);

    $(buildFormName).submit(formSubmitHandler);
}); 

function formSubmitHandler(){
   // process form data here...

   $.post( process.php ,$(this).serialize(),function(msg){

   }
}

Try replacing this with e.target, see if that helps.

$(buildFormName).submit(function(e) {
    // process form data here...
    $.post( process.php , $(e.target).serialize(), function(msg) {
}




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签