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

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.