i want to add multiple texboxes on button click and store that value in database can any one help me out how to do this i know some javascrip and jquery neede but don't know how to store the all texbox value to database because for multiple texboxes in database field is only one hope any one understand what is the question
AARTI SHRIVAS 2 Posting Pro in Training
diafol
You need to set the name of added textboxes to the same array name, .e.g.:
<input name="txt[]" />
You then collect the data with this:
$txt = (array) $_POST['txt'];
$txt will now contain an array of all textbox values. You can filter out blanks with array_filter().
AARTI SHRIVAS 2 Posting Pro in Training
@diafol
thak you for reply i did same thing and now i can store value in database
AARTI SHRIVAS 2 Posting Pro in Training
what i did it is in code that i have posted
<?php
session_start();
include('connection.php');
$category=array('anti mutagens'=>'anti mutagens','anti inflammatories'=>'anti inflammatories','anti oxidants'=>'anti oxidants','Signal transduction modulators'=>'Signal transduction modulators','Agents targeting members of the nuclear receptor superfamily'=>'Agents targeting members of the nuclear receptor superfamily','Proteasome inhibitor'=>'Proteasome inhibitor','Epigenetic Targeting Agents'=>'Epigenetic Targeting Agents');
$nature_com=array('Terpenoids'=>'Terpenoids','Flavonoids'=>'Flavonoids','Alkaloids'=>'Alkaloids','Oxygen heterocycles'=>'Oxygen heterocycles','Benzopyranoids'=>' Benzopyranoids','Polyketides'=>'Polyketides','Benzofuranoids'=>'Benzofuranoids','Lignans'=>'Lignans','Aliphatic natural products'=>'Aliphatic natural products','Polycyclic aromatic natural products'=>'Polycyclic aromatic natural products','Aminoacids and peptides'=>'Aminoacids and peptides');
$more=array("",);
$more1=array("",);
//add more textbox
if(isset($_POST['add']))
{
$more=$_POST['t_name'];
$more=$_POST['t2_name'];
$more[]="";
}
$t_name="";
$t2_name="";
$parameter="";
$a_target="";
$b_target="";
$value="";
$compound="";
if(isset($_POST['sub']))
{
$t_name=$_POST['t_name'];
$t2_name=$_POST['t2_name'];
$a_target=$_POST['target_a'];
$b_target=$_POST['target_b'];
$value=$_POST['value'];
$parameter=$_POST['parameter'];
$compound=$_POST['compound'];
$selected_sp_id = "";
foreach ($t_name as $ids) {
$selected_sp_id .= $ids . ", ";
}
$selected_sp_id = substr($selected_sp_id, 0, -2);
$selected_sp_id2 = "";
foreach ($t2_name as $ids1) {
$selected_sp_id2 .= $ids1 . ", ";
}
$selected_sp_id2 = substr($selected_sp_id2, 0, -2);
if($compound==0)
{
echo "<script>alert('Please select compound and target category!')</script>";
}
else
{
$insert="insert into `target`(`target_id`,`compound_id`,`exp_target`,`put_target`,`target_cat_exp`,`target_cat_put`,`ic50value`,`docking_parameter`) values(null,'$compound','$selected_sp_id','$selected_sp_id2','$a_target','$b_target','$value','$parameter')";
$insert_result=mysql_query($insert);
if(!$insert_result)
{
die(mysql_error());
}
echo "<script>alert('Target inserted success fully')</script>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<link href="new.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form method="post">
<div class="wrapper">
<?php include('header.php');?>
<div class="contant clearfix" style="background-color:#f4f4e8; margin-bottom:10px; border-radius:8px;">
<div class="admin_sign1 clearfix" >
<div class="compound_part_two">
<h3>Target List</h3>
<div class="target_left">
Compound Name:
<select name="compound">
<option value="0">---please select compound---</option>
<?php
$select="select `compound_id`,`name` from `compound`";
$result=mysql_query($select);
while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo $row['compound_id'];?>"><?php echo $row['name'];?></option>
<?php }?>
</select>
<h2>a)Experimental Proven targets: </h2>
<h4>Select Category of Target </h4>
<?php foreach($category as $key=>$value)
{?>
<div>
<input type="radio" name="target_a" value="<?php echo $key;?>" checked="checked"/><?php echo $value;?>
</div>
<?php }?>
<ul style="margin-top:20px !important;">
<li>IC50 Value:</li>
</ul>
<ul style="margin-top:20px !important;">
<li><input type="text" name="value" /></li>
<li> </li>
</ul>
</div>
<div class="target_right" style="margin-top:20px;">
<h2>b)Putative targets identified by Reverse screening:</h2>
<h4>Select Category of Target </h4>
<?php foreach($category as $key1=>$value1)
{?>
<div>
<input type="radio" name="target_b" value="<?php echo $key1;?>" checked="checked"/><?php echo $value1;?>
</div>
<?php }?>
<ul style="margin-top:20px !important;">
<li>Docking Parameters:</li>
</ul>
<ul style="margin-top:20px !important;">
<li><input type="text" name="parameter" /></li>
<li>
</li>
<li> </li>
</ul>
</div>
</div>
</div>
<div style="width:100%; height:auto;">
<div style="float:left; margin-left:150px;" >
<?php $i=0;
foreach($more as $m)
{
$i++;?>
Experimental targets Name:<br/>
<input type="text" name="t_name[]" value="<?php echo $m; ?>" /><br /><br />
<?php }?>
</div>
<div style="float:right; margin-right:150px;" >
<?php $i=0;
foreach($more as $m1)
{
$i++;?>
putative targets Name:<br/>
<input type="text" name="t2_name[]" value="<?php echo $m1; ?>"/><br /><br />
<?php }?>
</div>
<div style="clear:both; width:100%; height:auto;
padding-top:10px; text-align:center;">
<input type="submit" name="add" value="click to add more texbox">
</div>
</div>
<div style="clear:both;">
<input type="submit" name="sub" value="" class="submit" style="float:left; margin-left:150px;" />
<input type="submit" name="back" value="" class="back" style="float:right; margin-right:150px;"/>
</div>
</div>
</div>
</form>
</body>
</html>
now the problem is that when i click to add more texbox button the page is reloed i don't want to reload the page and for inserting all values in db i wil luse another button can any one have better idea to generate multiple text boxes
AARTI SHRIVAS 2 Posting Pro in Training
<html>
<head>
<title>jQuery add / remove textbox example</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<style type="text/css">
div{
padding:8px;
}
</style>
</head>
<body>
<h1>jQuery add / remove textbox example</h1>
<script type="text/javascript">
$(document).ready(function(){
var counter = 2;
$("#addButton").click(function () {
if(counter>10){
alert("Only 10 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.after().html('<label>Textbox #'+ counter + ' : </label>' +
'<input type="text" name="textbox' + counter +
'" id="textbox' + counter + '" value="" >');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
});
$("#removeButton").click(function () {
if(counter==1){
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" + counter).remove();
});
$("#getButtonValue").click(function () {
var msg = '';
for(i=1; i<counter; i++){
msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
}
alert(msg);
});
});
</script>
</head><body>
<div id='TextBoxesGroup'>
<div id="TextBoxDiv1">
<label>Textbox #1 : </label><input type="text" id='textbox1' >
</div>
</div>
<input type='button' value='Add Button' id='addButton'>
<input type='button' value='Remove Button' id='removeButton'>
<input type='button' value='Get TextBox Value' id='getButtonValue'>
</body>
</html>
i found this code it is perfect i just want to know how can i store the $msg value to database please help me i stuck in the middle of project and client want this changes quickly.........
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.