Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to retreive multiple textbox value into javascript

    Store Information to multiple textboxes from database


    Code:
    $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


    Code:
    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

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,721
    Thanks
    25
    Thanked 662 Times in 661 Posts
    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:
    Code:
    <?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:


    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •