Jump to content

[SOLVED] How do I echo out a semicolon?


lpxxfaintxx

Recommended Posts

Basically, this is what I want to output:

 

<li onselect="this.text.value = 'name'; document.getElementById('schoolID').value = 'id'; ">
name
</li>

 

I have tried the following:

 

echo '<li onselect="this.text.value = '.$name.'; document.getElementById('schoolID').value ='.$id.' \; ">$name</li>n';

 

But because of the semicolon, it thinks that the echo ENDS where the semicolon is. Any way to work around that? Thanks

Link to comment
https://forums.phpfreaks.com/topic/144428-solved-how-do-i-echo-out-a-semicolon/
Share on other sites

It's not the semicolon, it's your single quotes around schoolID

 

<?php
echo '<li onselect="this.text.value = '.$name.'; document.getElementById('schoolID').value ='.$id.'; ">$name</li>n';

 

see? Try...

 

<?php
echo '<li onselect="this.text.value = '.$name.'; document.getElementById(\'schoolID\').value ='.$id.'; ">$name</li>n';

WOW, I feel so stupid now. One thing though...

 

It echos out the literal '$name', not the value stored in $name. I made sure that the correct values were stored in $name and $id. Any idea what's up?

 

	while ($row = mysql_fetch_array( $results )) {
	$id = $row["ID"];
	$name = ucwords( strtolower( $row["School_name"] ) );
	$name = preg_replace("/(" . $q . ")/i", "<b>$1</b>", $name);


	echo '<li onselect="this.text.value = '.$name.'; document.getElementById(\'schoolID\').value ='.$id.'; ">$name</li>n';		



}

 

Once again, I made sure that values were indeed stored in $name and $id, but currently its echoing out literally "$name" and $id"

 

Thanks!

 

Replace

echo '<li onselect="this.text.value = '.$name.'; document.getElementById(\'schoolID\').value ='.$id.'; ">$name</li>n';	

with:

echo '<li onselect="this.text.value = '.$name.'; document.getElementById(\'schoolID\').value ='.$id.'; ">'.$name.'</li>n';

 

You need to take the variable out of the quotes ;) Syntax highlighting will help you in this case.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.