...

View Full Version : How to retreive multiple textbox value into javascript



minazfath
01-17-2012, 03:58 PM
Store Information to multiple textboxes from database



$count=<mysql_num_rows($query1);

for($i=0;$i<mysql_num_rows($query1);$i++)
{
$row1=mysql_fetch_array($query1);
$getval[$i]=$row1[UserId];
Print "<input type=text name='txtbox[]' id='txtbox[]' value='.$getval[$i].'">;
}


then i call a javascript function

Print "<script language=javascript>Call_Fun($count)</script>";


The above code store data into textbox and call the js function

in .js file



function Call_Fun(count)
{
for(var i=0;i<count;i++)
{
alert(document.getElementbyId('txtbox')+i.value);
}
}

But it doesn't retreive values in .js

Thankyou all

sunfighter
01-18-2012, 03:06 PM
How do you run your code minazfath? Do have a server on your computer or do have a test site? I ask because your php throws errors all over the place. And when run looking at the source code of the generated HTML tells a story.

PHP errors:
$getval[$i]=$row1[UserId];
S/B
$getval[$i]=$row1['UserId'];
And why do that? Can't you just use $row1['UserId']?
AND
Print "<input type=text name='txtbox[]' id='txtbox[]' value='.$getval[$i].'">;
S/B
Print "<input type=text name='txtbox[]' id='txtbox[]' value='.$getval[$i].'>";

I ran the php with some changes. This is what I ran:

<?php
$row1['UserId'] = 'tom';

for($i=0;$i<10;$i++)
{
//$row1=mysql_fetch_array($query1);
$getval[$i]=$row1['UserId'];
Print "<input type=text name='txtbox[]' id='txtbox[]' value='.$getval[$i].'>";
}
?>

This is what the output looks like:
http://i815.photobucket.com/albums/zz74/sunfighter41/cp.png

Do you really want those dots in the input text box?

And this is what the HTML code for a box looks like:
<input type=text name='txtbox[]' id='txtbox[]' value='.tom.'>

Do you see the problem? I think you can fix this yourself now you've learned some trouble shooting.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum