Hi; I suspect this is going to be a java-scripty thing (not too much experience with this).

Say I am showing a visitor a list of items in a table and they are allowed to make a selection with a checkbox at the end of each row. (I would usually set the whole table up as a form, and then have a submit button to send all the checked records into a MySQL table.) This, I know how to do with .php

However, I know it is possible to use a checkbox as a submit control...I was just wondering if (maybe with javascript), clicking the box would do the following invisibly in the backrground:
1) leave the table display up without need to reload.
2) leave the clicked checkbox(es) in a clicked state.
3) use the value(s) held in the checkbox code as the record (each checkbox is it's own form)
3) save the record for future reference in the MySQL table on the server.

Thanks for any specifics, links to code samples, etc. on this.

    Joseph Sliker;11038693 wrote:

    I know it is possible to use a checkbox as a submit control

    Not sure how you "know" this, but that's definitely false. A checkbox is a checkbox; a submit button is a submit button. The two have separate roles; without some sort of client-side scripting, you can't change those roles.

    It sounds like you want to use Javascript to add a hook to the checkboxes' "onclick" handlers such that you can perform some AJAX in the background to "submit" the selection to a PHP script on your server. Probably the easiest way to do this would be to use jQuery; see its .click() and .ajax() methods.

      Thanks, yes, that is exactly the sort of thing I (in my ignorance) was trying to get at, the onClick="this.form.submit();" type stuff, just not sure about how to do this exactly...gotta put those <link ...blah blah /jquery > things up in the header and figure out how to make them do something.

      I'm digging in to this stuff now, but I come here to kind of verbally sort these problems out and so many folks here are so good at nudging me in the right direction. Much appreciated.

        I might use an onchange event (instead of onclick), and then in the triggered function check the "checked" attribute of the checkbox to see if is actually checked as a result of that change. (I.e. you probably don't want to fire off your submit if they subsequently uncheck the box? (And what do you want to do if they repeatedly check/uncheck it?)

          NogDog;11038759 wrote:

          (I.e. you probably don't want to fire off your submit if they subsequently uncheck the box? (And what do you want to do if they repeatedly check/uncheck it?)

          As someone who has written lisp, I hate that your parentheses are not balanced.

          PS. onchange i better than onclick, because it will capture if the checkbox is checked/unchecked via the keyboard, because no one says you have to use your mouse to check it. 🙂

            Derokorian;11038761 wrote:

            PS. onchange i better than onclick, because it will capture if the checkbox is checked/unchecked via the keyboard, because no one says you have to use your mouse to check it. 🙂

            You know, I had thought about that right after I posted it. I wasn't sure if onclick specifically meant a mouse was used to interact with the element. (I suppose its naming scheme plus the existence of "onchange" should have made the answer rather apparent.)

            I meant to go and test that, but then I got busy and forgot. 🙂

            (EDIT:
                (For my '(friend Derokorian)
                    (this should really annoy you.
              Derokorian;11038761 wrote:

              As someone who has written lisp, I hate that your parentheses are not balanced.

              PS. onchange i better than onclick, because it will capture if the checkbox is checked/unchecked via the keyboard, because no one says you have to use your mouse to check it. 🙂

              Hopefully my code, parses better than my forum posts;

                Write a Reply...