954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Funny character generated when building onClick

Dear All,
I have function where I read from a mysql table a set of value. Part of my codes is like this

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 why the same value appear properly in the 21060R 22.567 but in the previous line is showing me like this 22.567')="" onclick="selectAndUpdate('21060R"> any idea?

<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>
newbie14
Posting Pro
544 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

The HTML code (second snippet) seem not to be generated from the PHP code in the first snippet since PHP code says id='gridRow' (single quotes) and HTML generated is id="gridRow" (double quotes)

I would code like this (all HTML attributes in double quotes):

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>";


Maybe my reply is not directly related to your question but the coding should be correct at first place to make it easier to spot the cause of the problem.

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

I tried your code and get HTML without an error. The only thing I changed was I surrounded all the indexes of the $row1 array with single quotes like

$row1['SerialNo']
broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

Also surround the argument of onclick attribute with escaped double quotes like:

onClick=\"selectAndUpdate('$row1[size]')\"


(this is only recommendation from W3C).

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

Hi Newbie,
Check this link
http://www.daniweb.com/web-development/php/threads/369623/1588766#post1588766
it will guide you how string concatenation works in php.

vibhaJ
Posting Shark
931 posts since Apr 2010
Reputation Points: 161
Solved Threads: 183
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You