Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A foolish question!

Status
Not open for further replies.

Geminist

Programmer
Jul 6, 2002
25
CN
I'm writing a php file to display a table and there's a link in every row.When clicked,the hyperlink leads to a new browser window.Each link needs a viriable to show in alertbox.
My php code:
<tr>
<td>.....</td>
..
..
<td><? echo &quot;<a href='PDelPaper.php?Type=One&sPaperID=$rowpart[PaperID]' onclick='return makesureone(&quot;.$rowpart[PaperName].&quot;);'>Delete</a>&quot;;?></td>

The makesureone function:
<SCRIPT language=JavaScript>
function makesureone(papername)
{
var agree = confirm(&quot;Are you sure to delete&quot;+papername+&quot;£¿&quot;);
if (agree)
return true;
else
return false;
}

</SCRIPT>
The problem is that it only works when the $rowpart[PaperName] is numeric,not when it's string.

Can u help me?thx~~~
 
I think its to do with the double quotes in the makesureone function. Im not entirely sure how you insert php variables into string but the problem probably is that
 
I would agree that quotes are the issue, your output line (echo) needs some escape characters and quotes in the parantheses because if you leave the quotes out it will treat the string as an object in javascript, which means your javascript alert in the function will probably insert the word object in the alert rather than the string:
Code:
<td><? echo &quot;<a href='PDelPaper.php?Type=One&sPaperID=$rowpart[PaperID]' onclick='return makesureone(
\'
Code:
&quot;.$rowpart[PaperName].&quot;
\'
Code:
);'>Delete</a>&quot;;?></td>

Now you are passing a string rather than an object. The reason this worked with a number is because numbers do not need the quotes like strings do. The backslash is the escape character in javascript to print the quote...not sure if this still solves it since it may cause the html tag to truncate the javascript function on the first escaped single quote...you may need to switch to double quotes and use the PHP escape character to print them in there without breaking from the string.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
This space has nothing in it, it's all ni your imagination
 
No,it won't work.'cause in &quot; &quot; ,' doesn't need \
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top