How to pass values arguments to modal.show() function in Bootstrap

后端 未结 3 1640
时光取名叫无心
时光取名叫无心 2020-11-30 04:01

I have a page the shows a list of local cafes. When the user clicks on a certain cafe, a modal dialog is shown, that already has the \"cafe name\" pre-filled. The page conta

3条回答
  •  醉梦人生
    2020-11-30 04:44

    I want to share how I did this. I spent the last few days rattling my head with how to pass a couple of parameters to the bootstrap modal dialog. After much head bashing, I came up with a rather simple way of doing this.

    Here is my modal code:

    
    

    And here is the simple javascript to change the gid, and gname input values:

    function editGroupName(id, name) {
        $('input#gid').val(id);
        $('input#gname.form-control').val(name);
      }
    

    I just used the onclick event in a link:

    //                                                                              ' is single quote
    //                                                                                   ('1', 'admin')
    edit
    

    The onclick fires first, changing the value property of the input boxes, so when the dialog pops up, values are in place for the form to submit.

    I hope this helps someone someday. Cheers.

提交回复
热议问题