submit using checkbox

Posted on 2009-02-11
Last Modified: 2012-05-06
i wonder if we can manipulate checkbox into submit button. what i mean i everytime user tick the checkbox, the value of checkbox will be send into database immediately. anyone can show me how to do that...?
Question by:niurexx
    LVL 19

    Expert Comment

    I have the same request by in coldfusion
    LVL 2

    Expert Comment

    onclick="document.formname.submit();return false;"

    and then try

    onclick="if(this.checked) this.form.submit();" ..after renaming the submit button!      
    LVL 6

    Accepted Solution

    Try onchange
    <input type="checkbox" onchange='submit();'>

    Open in new window


    Author Comment

    can someone guide me how to do that...? i need to display list of data from database and i need to create paging.. the paging is not a problem, the prob is i need to create code that use ajax to submit the data when user tick the checkbox without refreshing or changing the page..

    Author Comment

    i've try to use onchange and it seems to be working. but i got a problem. when i tick the checkbox, it will be send on the database but the value became same with the first value of the data. can someone please check my code and make some changes. i dont know how.
    form :
    <script type="text/javascript">
    	function register(){
    			type: "POST",
    			url: "submit_data.php",
    			data: 	"id=" + document.getElementById("id").value,
    			success: function(html){
    $sql = "SELECT * FROM product"; 
    $run = mysql_query ($sql);
    ?><form action="" method="post"><?
    while ($p =  mysql_fetch_array ($run)) {
    	echo '<input type=checkbox id=id value='.$p[id].' onChange=register();>'.$p['product_name'].'<br>';
    submit_data.php :
        $id        = htmlspecialchars(trim($_POST['id']));
        $addClient  = "INSERT INTO license (title) VALUES ('$id')";
        mysql_query ($addClient) or die(mysql_error());

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now