Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to grab values of checkbox and dropdown box within same page

Status
Not open for further replies.

david55

Programmer
Oct 23, 2007
6
NL
Hi all . I got a few check boxes in page with a drop down box. I want post the values of check boxes and drop down box to the same php page and insert them in to database using php. 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).I don't want to use different script to grab the values, i just want to use the same script where the check boxes are.My current code doesn't post correctly and i don't know how to grab check box values.I be happy if some one help me with it.Thanks



Code:
<html>
<head>
<title>Implementing Paging with next and prev</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

	<script type="text/javascript" src="./AJAX-vfl28003.js"></script>
<script type="text/javascript">
	function hasSelectedVideos()
	{
		var v_selected = false;
		var form = document.listform;

		for (var i=0; i < form.elements.length; i++)
		{
			var e = form.elements[i];
			if (e.type == "checkbox" && e.name == "selected_id" && e.checked == true)
			{
				v_selected = true;
			}
		}
		return v_selected;
	}

	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>





</head>

<body>
<?php


$value2 = $_POST['value'];

echo $value2;


$server   = "localhost"; // MySQL hostname
$username = "root"; // MySQL username
$password = "?????"; // MySQL password
$dbname   = "test"; // MySQL db name

$db = mysql_connect($server, $username, $password) or die(mysql_error());
      mysql_select_db($dbname) or die(mysql_error());

$sql = "SHOW TABLES FROM videoz ";


$result2 = mysql_query( $sql );


//this line for dropdownbox
$option = "";
$numbers=0;



while($row2 = mysql_fetch_row($result2))
{

$numbers++; // counting number of records
//This 2 line for drop downbox
extract ($row2);
    //$option .= "<option value=\"$row2[0]\">{$row2[0]}</option>\r\n";
    $option .= "<option value='{$row2[0]}'>{$row2[0]}</option>";


} 

?>

        <form method="post" name="listform">
            
			  <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 selected>- - - - - - - - -</option>

<?php echo $option; ?>

</select>&nbsp; </p>
       
<?

$query  = "SELECT idyoutube,thumbnail_url,title,view_count,comment_count FROM videos2";
$result = mysql_query($query) or die('Error, query failed');

// print the random numbers
while($row = @mysql_fetch_array($result)) {

?>

<input type="checkbox" id="checkbox_a4X7eFbP3u4" name="selected_id" value="<?php echo $row["idyoutube"] ?>" onClick="changeTableRowBG('a4X7eFbP3u4');">
	


	<table class="fr_thumb" bgcolor="#FFFFFF"><tr><td style="padding:0"><a href="./player.php?videoid=<?php echo $row["idyoutube"] ?>"><img width="120" class="frontPageRecentThumb" height="90"  border="0" src="<?php echo $row["thumbnail_url"] ?>"></a></td></tr></table><br />


  <TR><TD vAlign=top align="center">
                                <DIV style="FONT-WEIGHT: bold; FONT-SIZE: 12px"><a href="./pagingplayer.php?videoid=<?php echo $row["idyoutube"] ?>"><?php echo $row["title"] ?></a></DIV>
                                <DIV style="FONT-SIZE: 11px; COLOR: #666666; PADDING-TOP: 2px; FONT-FAMILY: Arial, Helvetica, sans-serif">
                                &nbsp;Views: <?php echo $row["view_count"] ?> |  <?php echo $row["comment_count"] ?>: 0 </DIV><br />
				&nbsp;  
<hr>

<?

}
echo ' </form>';
echo '<br>';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top