Forum Moderators: coopster

Message Too Old, No Replies

PHP with javascript quote problem?!?

I dont really know whats going on but theres a problem with my links.

         

GamingLoft

9:55 pm on Dec 16, 2007 (gmt 0)

10+ Year Member



Ok heres my code.

<head>
<link rel="stylesheet" href="http://example.com/pbsbam/forums/templates/subSilver/subSilver.css"
type="text/css">
<script language="Javascript">
<!--
function selectAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
//-->
</script>

</head>
<body> <table width='100%'>
<form name='form'>

$tdcount = 1;
$numtd = 2; // number of cells per row

$idcheck = mysql_query("SELECT * FROM corners
ORDER BY `id` DESC LIMIT 4");

while($row = mysql_fetch_array($idcheck))
{
$imgurl = $row['imgurl'];
$name = $row['name'];
$id = $row['id'];

if ($tdcount == 1)
echo "<tr>";
echo "<td>
<center><img src='http://example.com/pbsbam/images/corners/" . $id . ".png' border='0'/><span class='gensmall'><br>"
. $name . "</span><br>
<a href='javascript:selectAll('form.area" . $id . "')>Select All</a><br>
<textarea rows='7' cols='48' name='area" . $id . "'>
<div style='position:absolute;
z-index:2;
right:0px;
top:0px'>
<a href='http://www.example.com'><img src='http://example.com/pbsbam/images/corners/" . $id . ".png'
border='0' alt='PBSbam.com'/>
</a></div>
</textarea>
<span class='gensmall'><br>Paste this code into you're ''About me'' on Myspace.<br></span>";
echo "___________</center><br><br></td>"; // display as you like
if ($tdcount == $numtd)
{
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}

if ($tdcount!= 1)
{
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++; } echo "</tr>";
}
?>
</form>
</table>

I have a feeling the problem is on this line because my A hrefs always come out wrong like this:

javascript:selectAll(

I think i might have to use double quotes in the php somehow but i honestly havent gotten a clue

the link should be coming out

javascript:selectAll("form.area1")

[edited by: dreamcatcher at 11:12 am (utc) on Dec. 17, 2007]
[edit reason] use example.com / thanks [/edit]

PHP_Chimp

10:15 pm on Dec 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are a load of problems -
HTML attributes are quoted with " not '. So you cant use
<a href='http://www.example.com'><img src='http://example.com/pbsbam/images/corners/" . $id . ".png'
border='0' alt='example.com.com'/>

As the href is quoted with ' as is the src. There are loads of them in your code.

ALL HTML attributes need to have ", so you can use ' in the php to echo '...' if you want to avoid having to escape every ", but you cant use ' in your HTML.

[edited by: dreamcatcher at 11:12 am (utc) on Dec. 17, 2007]
[edit reason] use example.com / thanks [/edit]

RonPK

1:01 pm on Dec 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HTML attributes are quoted with " not '.

For the record: in HTML the single quote will do fine.

HTML 4.01 specs: [w3.org...]

In XHTML all attributes need to be quoted: [w3.org...] . Both double and single quotes are accepted.