Form, Checkbox, and MySQL - Page 2

Form, Checkbox, and MySQL

2»

Replies

  • allanallan Posts: 63,113Questions: 1Answers: 10,397 Site admin
    Excellent - good to hear we got it sorted in the end.

    It's probably worth your time having a look through that code and understanding what is happening with it :-).

    Regards,
    Allan
  • JustLikeIcarusJustLikeIcarus Posts: 8Questions: 0Answers: 0
    edited September 2009
    Hey everyone. I was looking through all the different solutions to this and was surprised that while all of them are good, none took full advantage of jQuery's power. Here is basically the code I use for this same situation to show you what I mean.
    [code]
    $('#form').submit( function() {
    $('input', otable.fnGetNodes()).each(function(){
    if($(this).is(':checked')){
    $(this).appendTo('#form');
    }
    });
    });

    oTable = ..... invoke your data table as usual.
    [/code]

    I think this accomplishes the same as all the other solutions but is less code. And now that i think about it this would be even shorter. since appendTo moves the item and doesnt clone it.
    [code]
    $('#form').submit( function() {
    $('input:checked', otable.fnGetNodes()).appendTo('#form');
    });

    oTable = ..... invoke your data table as usual.
    [/code]


    let me know your thoughts.
  • allanallan Posts: 63,113Questions: 1Answers: 10,397 Site admin
    Hi JustLikeIcarus,

    Looks good to me! There are two cases I can think of off the top of my head where it might not be 100% appropriate to use your solution: 1. If you are using Ajax, the input elements are moved around the document, i.e. outside the table - 2. If you want the checkboxes to be submitted even when not checked (possibly useful for some server-side processing). Having said that, for the case where you are reloading the page and just want the checked inputted, your code is absolutely ideal! Thanks for sharing it with us :-)

    Regards,
    Allan
  • JustLikeIcarusJustLikeIcarus Posts: 8Questions: 0Answers: 0
    Hey Allan. Yes you are correct, that example has a few limitations. Namely the ones you mentioned. In the end if it works for your situation then its a success.
  • mickeymicmickeymic Posts: 23Questions: 0Answers: 0
    Hello,

    Just a last question about your solution allan, how can I adapt this function :

    [code]function verifselection() {

    n = 0;
    temp = document.main.elements.length;

    for (i=1; i
  • allanallan Posts: 63,113Questions: 1Answers: 10,397 Site admin
    Hi mickeymic,

    You have a confirm already, and then submit the form. When do you want the delete to occur? After the page has reloaded? In that case you will need your PHP output the required Javascript. Worth reading some of these articles: http://www.google.com/search?hl=en&source=hp&fkt=1173&fsdt=7994&q=using+alert+to+debug+javascript&aq=f&oq=&aqi=

    Allan
  • mickeymicmickeymic Posts: 23Questions: 0Answers: 0
    Hello Allan,

    Thanks, I find a solution

    Bye

    ;D)
  • smg6511smg6511 Posts: 12Questions: 2Answers: 0
    edited October 2009
    Hello all,

    I like JustLikeIcarus's brevity ...

    [code]
    $('#form').submit( function() {
    $('input:checked', otable.fnGetNodes()).appendTo('#form');
    });
    [/code]

    The only trouble for me is that the inserted inputs show briefly before the page redirects. To make this more graceful, how would one set the attr("type","hidden") to these injected elements?

    Thanks,
    Jim
  • allanallan Posts: 63,113Questions: 1Answers: 10,397 Site admin
    edited October 2009
    Does:

    [code]
    $('#form').submit( function() {
    $('input:checked', otable.fnGetNodes()).attr("visibility","hidden").appendTo('#form');
    });
    [/code]
    work (or something like that - perhaps it should be using css()?)?

    Allan
  • smg6511smg6511 Posts: 12Questions: 2Answers: 0
    Thanks, Allan. This is almost there ... doing the above (and changing attr("visibility","hidden") to css("display","none")) does take care of the visibility issue of the newly inserted elements. However, I'm realizing that this is removing the input from its original position in the DOM ... which is briefly noticeable (the checked inputs disappear before the page refreshes).

    Question: Is each page (DT pagination-wise) a node? If so, how do I identify (and exclude) the currently displayed node/page from the search? I'm thinking the way to do this is to use the jquery clone() function for inputs not shown in the current node/page.

    Cheers,
    Jim
  • allanallan Posts: 63,113Questions: 1Answers: 10,397 Site admin
    Hi Jim,

    Good to hear that works. To exclude nodes which are currently visible in the DOM, you could do something like, $('input:checked'); (to get an array of nodes from the current DOM only) and then cross check between your array from fnGetNodes() and this new array - if an element is in both, then it's on the current page, and shouldn't be moved. jQuery even provides $.unique() which might be used for this: http://docs.jquery.com/Utilities/jQuery.unique#array

    Regards,
    Allan
  • BlalienBlalien Posts: 17Questions: 0Answers: 0
    Is there a possibility to send the form to a page of choice?
    So that the page of choice will be loaded or reloaded and that the post values have been sent.

    I need to send the form to send to a file (Doesn't matter which one), but the current page needs to be reloaded.

    Greetz
This discussion has been closed.