Web Analytics Made Easy -
StatCounter Space causing problem in generating onClick - CodingForum

Announcement

Collapse
No announcement yet.

Space causing problem in generating onClick

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Space causing problem in generating onClick

    Dear All,
    I have function where I read from a mysql table a set of value. Part of my codes is like this. The problem why I need to use fully php here is this a ajax called page.


    Code:
    echo "<tr id='gridRow'>
     <td >$count</td>
     <td> <input type='checkbox' onClick=selectAndUpdate('$row1[size]')></td>
     <td> {$row1[SerialNo]}</td> 
     <td> {$row1[InHouseBranding]}</td> 
     <td> {$row1[BrandCode]}</td> 
     <td> {$row1[size]}</td> 
     <td> {$row1[Pattern]}</td>  
     <td> {$row1[EntryStatus]}</td>   
     </tr>";

    A sample row generated is as below can you notice this line <input type="checkbox" 22.567')="" onclick="selectAndUpdate('21060R"> why the same value appear properly in the <td> 21060R 22.567</td> but in the previous line is showing me like this 22.567')="" onclick="selectAndUpdate('21060R"> any idea?


    Code:
    <tr id="gridRow">
    <td>1</td>
    <td>
    <input type="checkbox" 22.567')="" onclick="selectAndUpdate('21060R">
    </td>
    <td> EA12</td>
    <td> BOR1</td>
    <td> GY</td>
    <td> 21060R 22.567</td>
    <td> HMG 2020</td>
    <td> New</td>
    </tr>

  • #2
    The php code you posted is not the code that creates the html code you posted because in the php code you have single quotes around the id and the html has double quotes

    Code:
    echo "<tr id='gridRow'>
     <td >$count</td>
     <td> <input type='checkbox' onClick=selectAndUpdate('$row1[size]')></td>
    Code:
    <tr id="gridRow">
    <td>1</td>
    <td>
    If that echo created the html, then gridRow would have had single and not double quotes around it.

    Also, if that echo is in a loop then you are going to have multiple rows with the same id which is invalid. Id's must be unique on a web page.
    Last edited by webdev1958; Aug 21, 2011, 10:53 PM.

    Comment


    • #3
      Dear Webdev,
      I have remove the id and to my surprise I add the single quote and it comes out as a double quote. To further remove the confusion here is my page which generates the problem. I know the problem happens when my data have a space or /. Here is a sample link http://183.78.169.53/tm/tyreDetails.php?tyre=14. Below is the codes which I use to generate it. Can you see you get an error of unterminated string?

      Code:
      while($row1 = mysqli_fetch_array($result, MYSQL_ASSOC))
      {
       $count++;
        $tyreSize = $row1[tyreSize];
       echo "<tr>";
       echo "<td >$count</td>";
       echo "<td>"; 
       echo "<input type='checkbox' onClick=selectAndUpdate('$row1[tyreSize]')></";
       echo "</td>";
       echo "<td> {$row1[tyreSerialNo]}</td>"; 
       echo "<td> {$row1[tyreInHouseBranding]}</td>"; 
       echo "<td> {$row1[tyreBrandCode]}</td>"; 
       echo "<td> {$row1[tyreSize]}</td>"; 
       echo "<td> {$row1[tyrePattern]}</td>";  
       echo "<td> {$row1[tyreEntryStatus]}</td>";   
       echo "</tr>";
       
      }

      Comment


      • #4
        Originally posted by newbie14 View Post
        Can you see you get an error of unterminated string?
        I'm not getting any error message when I select an option from the select list.

        But you have an error in this line.

        echo "<input type='checkbox' onClick=selectAndUpdate('$row1[tyreSize]')></";

        Comment


        • #5
          Try to use the string concatenate operator "." instead of the literal notation
          Code:
          echo "<input type=\"checkbox\" onClick=\"selectAndUpdate('" . $row1[tyreSize] . "')\">";

          Comment


          • #6
            Originally posted by webdev1958 View Post
            I'm not getting any error message when I select an option from the select list.

            But you have an error in this line.

            echo "<input type='checkbox' onClick=selectAndUpdate('$row1[tyreSize]')></";
            and I think you'll need quotes around tyreSize.

            Which line did your error message say the error occurred in?
            Last edited by webdev1958; Aug 22, 2011, 11:44 AM.

            Comment


            • #7
              Dear Dev,
              Yes looks like your method works now. If I have multiple parameters for the function how to split them then? I have done this is it ok echo "<input type=\"checkbox\" onClick=\"selectAndUpdate('" . $row1[tyreSerialNo] . "','" . $row1[tyreSize] . "')\">";?

              Comment


              • #8
                Originally posted by newbie14 View Post
                Dear Dev,
                Yes looks like your method works now. If I have multiple parameters for the function how to split them then? I have done this is it ok echo "<input type=\"checkbox\" onClick=\"selectAndUpdate('" . $row1[tyreSerialNo] . "','" . $row1[tyreSize] . "')\">";?
                split them how - in the sql, database table, output html table - I don't follow what you mean

                Comment

                Working...
                X