Open Source Tutorials - Open Source Training
Open source training & tutorials from experienced, passionate people
chrome icon firefox icon ie icon opera icon safari icon Sings in these Browsers
A- A A+

By A Web Design

Welcome, Guest
Username Password: Remember me

javascript and php dynamic buttons
(1 viewing) (1) Guest
All your queries regarding JavaScript will be solved in this forum
  • Page:
  • 1
TOPIC:

javascript and php dynamic buttons

javascript and php dynamic buttons 1 year ago #620

  • evas
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
hello there! i want to create dynamic buttons!after many tries and a lot of googling i ve create dynamic buttons from mysql.my problem is to name the buttons from the table in mysql ! i post my code to help me if anybody can/knows/wants

<?php
$connect=mysql_connect("localhost","admin","pass")
or die ("Check your server connectio");
$db_found = mysql_select_db("mydb", $connect);
$SQL = "SELECT * FROM mytable ";
$result = mysql_query($SQL);
$num_r = mysql_num_rows($result);
while($nt=mysql_fetch_array($result)){
$test[$num_r]=$nt['testing']; //test values in mytable

}
?>

function addsubmit (fid){ // a fun that create dynamicly buttons
var num = "<?php echo $num_r; ?>";
if (num >0) {
for (i=0;i<num;i++){
var newsubmit = document.createElement("input");
<?php $temp=$num_r--;?>
newsubmit.type = "button";
newsubmit.id = "mysubmit";
newsubmit.name = "mysubmit";
newsubmit.value ="<?php echo $test[$temp]; ?>";
newsubmit.on-click = function () {
fun(i);
};
fid.appendChild(newsubmit);
}
}
}
but it doesnt work!i also try
newsubmit.value ="<?php echo $test[3]; ?>";
but didnt get any result please help and sorry for my large msg

Re: javascript and php dynamic buttons 1 year ago #621

  • meher
May I know when is the addsubmit function is being invoked in your program?

Re: javascript and php dynamic buttons 12 months ago #622

  • evas
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
at body onload event! i ve tried something diferent and worked!
newsubmit.type = "button";
newsubmit.on-click = function () {
fun(i);
};
tnx for your response! i ve tried something diferent and worked!
newsubmit.type = "button";
newsubmit.on-click = function () {
fun(i);
};

But now i have an other problem ! i want each button to be named by a mysql table value.So a append my code
<?php
$connect=mysql_connect("localhost","admin","pass")
or die ("Check your server connection");
$db_found = mysql_select_db("mydb", $connect);
$SQL = "SELECT * FROM mytable ";
$result = mysql_query($SQL);
$num_r = mysql_num_rows($result);
while($nt=mysql_fetch_array($result)){
$test[$num_r]=$nt['testing'];
}
By here i have all the values of mysql table saved in an array $test.Now look at the script
?>
<s-cript language="javascript" type="text/j-avascript">
function addsubmit (fid){
var num = "<?php echo $num_r; ?>";
if (num >0) {
for (i=0;i<num;i++){
var newsubmit = document.createElement("input");
<?php $n=$num_r--;?>
data="<?php echo $test[$n]; ?>";

newsubmit.type = "button";
newsubmit.id = "mysubmit";
newsubmit.name = "mysubmit";
newsubmit.value =data;
newsubmit.on-click = function () {
fun(i);
};
fid.appendChild(newsubmit);
}
}
}
but with no result!if i try for test
data="<?php echo $test[2]; ?>"; ,it doesnt work again,if i try
data="<?php echo $test; ?>"; all the buttons are named Array.any ideas how will i make it work as i want ??

Re: javascript and php dynamic buttons 12 months ago #623

  • meher
You are calling a function on Body Load event. The function name is addsubmit. And in this function you are passing a value to the javascript method "addsubmit(fid)".

May i know what is the value as a parameter you are passing?
  • Page:
  • 1
Time to create page: 1.64 seconds
OSV Newsletter


Receive HTML?

NOTE: To prevent subscription to the OSV newsletter, uncheck the checkbox above.
Guest Blog for OSV
Free Ebook Download