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">
<span class="xxlargeText"><b>|</b></span> Copy Videos To:
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!!
Last edited by tony007; Oct 20th, 2007 at 09:36 AM.
Re: How to grab values of checkbox and dropdown box via post from within the same page
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.
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.
Re: How to grab values of checkbox and dropdown box via post from within the same page
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.
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.
Re: How to grab values of checkbox and dropdown box via post from within the same page
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!!!
Re: How to grab values of checkbox and dropdown box via post from within the same page
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:
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.