#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    134
    Rep Power
    10

    align text field in Form to centre


    I am trying to align an input field in a table to the centre. No probelm with a normal field/cell (as shown in line one columns 1 and 2 of the attached) but when it is an input field (next 10 lines) I cannot. I've tried css (though my knowledge is limited) but have failed. Can anyone help please? I've attached the basic code that I am using.

    Code:
    <?php 
    
    $a=array("1","2","3","4","5","6","7","8","9","10");
    $b=array("4","5","4","3","4","5","3","4","4","3");
    
    	$form ="<form method=\"post\">";  
        $form.="<table  border=\"1\"  cellspacing=\"0\" cellpadding=\"0\"> ";
    $form.="<tr>";
        $form.="<td width = \"10\" align = \"center\">A</td> ";
        $form.="<td width = \"10\" align = \"center\">B</td> ";
    
    $form.="</tr>";
    
    for ($i = 0;$i<=9;$i++)
    	{
    $form.="<tr>";
    $val = "t_".$i;
    $val1 = $a[$i];
    $form.="<td width = \"10\" align = \"center\"><input type=\"text\" name=".$val." value = ".$val1." ></td> ";
    $val2 = "v_".$i;
    $val3 = $b[$i];
    $form.="<td width = \"10\" align = \"center\"><input type=\"text\" name=".$val2." value = ".$val3." ></td> ";
    $form.="</tr>";
    	}
    
        $form.="</table>";
        $form.="</form>";
    echo ($form);
    
    ?>
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,896
    Rep Power
    9646
    Are you sure you don't mean to center the text in the textbox?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    134
    Rep Power
    10
    No, I'm trying to centre the text in the cell (i.e. in the column).

    However, I have found the solution.

    First by ensuring that there is a space after the equal signs.

    Secondly by replacing the code

    Code:
    $form.="<td width = \"10\" align = \"center\"><input type=\"text\" name=".$val." value = ".$val1." ></td> ";
    with

    Code:
    $form.= "<td width=\"10\" align =\"center\"><input type=\"text\" name= ".$val." value = \"$val1\"  style='text-align: center;'></td> ";
    Thank you
  6. #4
  7. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,896
    Rep Power
    9646
    The space has absolutely nothing to do with it.

    By the way, what you've done is centered the text in the textbox.

IMN logo majestic logo threadwatch logo seochat tools logo