1

Hi I'm writing a code to get the value of a textbox. Though all the other values prints perfectly well alert(FormID) prints as Undefined. Here I have clearly commented on what I'm getting. Please someone help me to show the mistake I have done.

<html>
<title></title>
<head>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script></head>
    <script src="UserTypeSubmit.js"></script></head>
<script>
$(document).ready(function(){

$(".FormEdit").click(function(){

var B=$(this).attr('id');// Ex: Getting ID as FormEdit1 if click on first Edit link
var ReplacesVal=B.replace("FormEdit","");//Prints Value as 1 a I I need.
alert("FormIDInput"+ReplacesVal);//Alert : FormIDInput1
var FormID=$("#FormIDInput"+ReplacesVal).val();
alert(FormID);// Alert: Undefine. Im expecting the value 1 to be in the alert as $("#FormIDInput"+ReplacesVal).val() is equal to 1. and it prints well in the text box.
});
return false;
});
</script>
</head>
<body>

    <div class="User" style="color:#0B173B">Forms_Available_to_Collect_Pubic_Health_Information </div>
<br><br>

        <?php
        include 'connectionPHP.php';

        $result=mysqli_query($con,"SELECT * FROM Form");
    echo "<table border='1' id='DisplayFormDetailss'>
    <tr style='background-color:#D0A9F5;' height='40px;'>
    <th width='100px;'>Form ID</th>
    <th width='420px;'>Form Name</th>
    <th width='100px;'>Inactivate</th>
    <th width='70px;'>Edit</th>
    <th width='70px;'>Delete</th>
    <th width='70px;'>Save</th>

    </tr>";

    $i=1;
        while($row = mysqli_fetch_array($result))
        {   

        $w=$row['Form_ID'];
        $v=$row['Form_Name'];

        echo "<tr height='25px;'>";
        echo "<input id='FormIDInput ".$i."' value='$w' ></input>";
        //Prints 1,2,3,4,5,6 as the values of input boxes perfectly.

        echo "<td name='FormID[]' class='FormID'  align='center' value='$w'>$w</td>";
        echo "<td name='FormName[]' id='FormName".$i."' align='left'>$row[Form_Name]</td>";
        echo "<td name='FormInactive[]' id='FormInactive".$i."' align='center'><input type='checkbox'></input></td>";
        echo "<td class='FormEdit' id='FormEdit".$i."' align='center'><a href='' align=left>Edit</a></td>";
        echo "<td name='FormDelete[]' id='FormDelete".$i."' align='center'><a href='' align=left>Delete</td>";
        echo "<td name='FormSave[]' id='FormSave".$i."' align='center'><a href='' align=left>Save</td>";

        echo "</tr>";
        $i++;
        }

        echo "</table>";


        ?>

</body> 
</html>
mcuadros
  • 4,098
  • 3
  • 37
  • 44
t4thilina
  • 2,097
  • 3
  • 18
  • 19
  • 1
    `id='FormIDInput ".$i."` I don't think you're supposed to have spaces in IDs – Popnoodles Dec 07 '13 at 06:38
  • 2
    Is it just me - these `` shouldn't exist. – Popnoodles Dec 07 '13 at 06:40
  • 1
    @popnoodles In XHTML and HTML5, the closing tag doesn't make much impact and can be even skipped all together (though should work equally fine if kept intact): http://stackoverflow.com/questions/3558119/are-self-closing-tags-valid-in-html5 – Pratyush Dec 07 '13 at 06:42
  • I've always self-closed them. Just checked, W3 says input can be either. – Popnoodles Dec 07 '13 at 06:43

3 Answers3

3

In your PHP code, there is a space in the input box:

 echo "<input id='FormIDInput ".$i."' value='$w' ></input>";

try to replace it with

 echo "<input id='FormIDInput".$i."' value='$w' ></input>";
Krish R
  • 22,583
  • 7
  • 50
  • 59
Pratyush
  • 5,108
  • 6
  • 41
  • 63
2

in input type filed missing type ='text' & space issue:

echo "<input type='text' id='FormIDInput".$i."' value='$w' ></input>";
Karthik
  • 1,428
  • 3
  • 17
  • 29
1

You need to use id='FormIDInput".$i."' instead of id='FormIDInput ".$i."'. And You can use the FormID[] input textfiled for FormIDInput

try using,

 echo "<td name='FormID[]' id='FormIDInput".$i."'  class='FormID'  align='center' value='$w'>$w</td>";

instead of

 echo "<input id='FormIDInput ".$i."' value='$w' ></input>";
 //Prints 1,2,3,4,5,6 as the values of input boxes perfectly.

 echo "<td name='FormID[]' class='FormID'  align='center' value='$w'>$w</td>";
Krish R
  • 22,583
  • 7
  • 50
  • 59