Results 1 to 13 of 13

Thread: How to grab values of checkbox and dropdown box via post from within the same page

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    How to grab values of checkbox and dropdown box via post from within the same page

    Hi all . I got a few checkboxes in page with a drop down box. I want post the value of checkbox to the same page and insert them in to database. could any one tell me how to grab those values from within the same page?(As you see my form is posting to same page)

    PHP Code:
    <script type="text/javascript">

    function doAction(action)
        {
            var e = document.createElement('input');
            e.setAttribute('type', 'hidden');
            e.setAttribute('name', action);
            e.setAttribute('value', "1");
            document.listform.appendChild(e);
            document.listform.submit();
        }

        function setCopyDst(copy_dst)
        {

     
            var e = document.createElement('input');
            e.setAttribute('type', 'hidden');
            e.setAttribute('name', "copy_dst");
            e.setAttribute('value', copy_dst);
            document.listform.appendChild(e);
        }

    function selectCopy(list)
        {    
            var index = list.selectedIndex;
            var value = list.options[index].value;
       setCopyDst(value);        
       doAction("action_copy");
        }

    </script>

     <form method="post" name="listform">
                
                  &nbsp; &nbsp;<span class="xxlargeText"><b>|</b></span>&nbsp; &nbsp;Copy Videos To:

    <select name="copy_to" onChange="selectCopy(this)">
     <option selected>- - - - - - - - -</option>

    <?php echo $option?>

    </select>&nbsp; </p>

    ......
    ......
    <input type="checkbox" id="<?php echo $row["id"?>" name="selected_id" value="<?php echo $row["idvalue"?>">
    Last edited by tony007; Oct 20th, 2007 at 09:28 AM.

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: How to grab value of post from within the same page

    something like this?

    HTML Code:
    <form method="post" name="listform" method="POST" action="<?php echo $_SERVER['self']; ?>">
                
    &nbsp; &nbsp;<span class="xxlargeText"><b>|</b></span>&nbsp; &nbsp;Copy Videos To:
    
    <select name="copy_to" onChange="selectCopy(this)">
    	<option selected>- - - - - - - - -</option>
    
    	<?php
    	if(isset($_POST['subm'])){
    		$check = $_POST['selected_id'];
    		if(trim($check) !== ''){
    			echo "<option>$check</\option>";
    		}
    	}
    	?>
    
    </select>&nbsp; </p>
    
    <input type="checkbox" id="<?php echo "test"; ?>" name="selected_id" value="<?php echo "CHECKBOX1"; ?>">Check1</input><br>
    <input type="submit" id="subm" name="subm" value="Submit" />
    </form>
    Delete it. They just clutter threads anyway.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    Thanks for youre reply. But i think i didn't explain it well. I want to collect values of checkboxes and dropdown box and then write them in to db using same page. Just like youtube where we select a few video checkbox and then copy it to diffrent playlists!! I want to achive that tast but don't know how to grab the values!!
    Attached Images Attached Images  
    Last edited by tony007; Oct 20th, 2007 at 09:36 AM.

  4. #4
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    Alright, what kind of database are you using?
    Delete it. They just clutter threads anyway.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    Quote Originally Posted by TheBigB
    Alright, what kind of database are you using?
    well i am using mysql database. The part that i really like is when i select a drop down box value it automatically collects the checkbox values and then send them to the same page and writes them to mysql in specified palylist from drop down box !! I tried to reuse youtube javascript but didn't figure out how it works!!!

    Note: i need to use checkbox values and the selected drop down box value. I need these information to write them to specific table in mysql db.
    Last edited by tony007; Oct 20th, 2007 at 09:47 AM.

  6. #6
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    Well, I can say that the javascript here is quite useless.

    Anyway, lets start with the database.
    Do you have a structure? If not, try developing one.
    If you want to have a multi-user system, I'd start with that first.
    Delete it. They just clutter threads anyway.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    Quote Originally Posted by TheBigB
    Well, I can say that the javascript here is quite useless.

    Anyway, lets start with the database.
    Do you have a structure? If not, try developing one.
    If you want to have a multi-user system, I'd start with that first.
    The way i want to create the database is to assign one table for each playlist and place all the checkbox values(video id) inside it.
    At this moment i just want to know how to pass check box values the way youtube passed them to the same script that has the checboxes and wrote them to mysql. i just want to create this for myown use not for multiuser. i might add that option later.
    Last edited by tony007; Oct 20th, 2007 at 10:34 AM.

  8. #8
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: How to grab values of checkbox and dropdown box via post from within the same pag

    Assigning one table for every playlist is not a good idea. A better idea would be to have 2 tables, one with playlist information (name, playlistid, membername, etc) and then have a videos table with all the videos on it (videoid, name, playlistid membername, etc.)

    So if you want to show all the videos from playlist 123, you simply do this:
    SELECT FROM `videos` WHERE playlist='123'

    Hope that helps.


    Lets start on your checkboxes...

    on the html page, you need to name all your checkboxes with some name (like videos) and then add brackets to the end:
    <input type='checkbox' name='videos[]' value=''>

    the brackets tell the php that is it an array.

    PHP Code:
    while (list ($key,$val) = @each ($_POST['videos'])) {
         
    //Ok, so when the form is posted you want to add this code
         //Here you do whatever you want to do with the videos: delete, move, etc

    Last edited by dclamp; Oct 20th, 2007 at 10:52 AM.
    My usual boring signature: Something

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    Quote Originally Posted by dclamp
    Assigning one table for every playlist is not a good idea. A better idea would be to have 2 tables, one with playlist information (name, playlistid, membername, etc) and then have a videos table with all the videos on it (videoid, name, playlistid membername, etc.)

    So if you want to show all the videos from playlist 123, you simply do this:
    SELECT FROM `videos` WHERE playlist='123'

    Hope that helps.
    dclamp thanks for your reply. But my question is not database design!! My question is about how to transfer checkbox values and dorp down box value via post method to the same page and write them to table or just echo them!!!

  10. #10
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    sorry for the confusion, i added to my last post. please read again
    My usual boring signature: Something

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    Quote Originally Posted by dclamp
    sorry for the confusion, i added to my last post. please read again
    i am not passing one checkbox value !! could you just look at youtube source code and tell me how it works? Youtube didn't use any sort of array.
    This is how they made their checkboxes:

    PHP Code:
    <tr valign="top">
        <
    td id="16XENujsU3zg" align="center" width="15">
        <
    input type="checkbox" id="checkbox_6XENujsU3zg" name="selected_id" value="6XENujsU3zg" onClick="changeTableRowBG('6XENujsU3zg');">
        </
    td
    This is how they created the dropdown box:

    PHP Code:
        <form method="post" name="listform">
                <
    div id="buttonsRow" class="controls" style="height:24px;">
                    <
    div id="buttonCopy" style="float:left;">
                      <
    input value="Remove Videos" name="action_remove_selected" type="submit" onClick="return confirmRemove();">
                      &
    nbsp; &nbsp;<span class="xxlargeText"><b>|</b></span>&nbsp; &nbsp;
                    
    Copy Videos To:     <select name="copy_to" onChange="selectCopy(this)">
        <
    option value="">------------</option>
        
        
        
        <
    option value="pl_1abc2dfdfD952FA">playlist1</option>
        

        
        <
    option value="pl_abc4BdfdfdfC11B">playlist2</option>
        

    </
    select
    after selecting a playlist to transfer to from drop down box selectCopy(this) function gets triggerd:

    <select name="copy_to" onChange="selectCopy(this)">


    and i don't know from there how the rest works. I hope some one explain to me how to make this thing work the way youtube done it.

  12. #12
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    actually, to your dismay, they are using an array with javascript. You are now using an array with php. If you want to use javascript of all of this, then maybe you should take a look at out Javascript forum.
    My usual boring signature: Something

  13. #13
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: How to grab values of checkbox and dropdown box via post from within the same page

    in php they know what checkbox values they are looking for, and just loop through it.
    Delete it. They just clutter threads anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width