Log in

View Full Version : Stumped!



e1seix
09-11-2007, 01:31 PM
what's wrong with this code that it is returning an error?


echo '<form action="/search.php" method="GET" style="margin-bottom:2px;margin-top:5px">';
echo '<input type="text" onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue" name="search" style="width:95px" value="keyword search">';
echo '<input type="hidden" name="startrow" value="0">';
echo '<input type="submit" value="Go!">';

have a feeling it's to do with this [onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue"] nested part of the code that empties the input box when clicked by the user?

boogyman
09-11-2007, 01:38 PM
break out of php mode when parsing



<?php
...
echo ?>
<form action="/search.php" method="get" style="margin-bottom:2px;margin-top:5px">
<input type="text" onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue" name="search" style="width:95px" value="keyword search">
<input type="hidden" name="startrow" value="0">
<input type="submit" value="Go!">
</form>
<?php
// resume php code


also


onfocus="this.value === this.defaultValue && (this.value = '')" onblur="this.value = this.value || this.defaultValue"

see
http://www.dynamicdrive.com/forums/showpost.php?p=108954&postcount=3

Twey
09-11-2007, 01:45 PM
You have single quotes inside of single quotes. Break out of PHP parsing mode to output complex data like HTML:
?>
<form action="/search.php" method="get" style="margin-bottom: 2px; margin-top: 5px;">
<input
type="text"
onfocus="this.value === this.defaultValue && (this.value = '');"
onblur="this.value = this.value || this.defaultValue;"
name="search"
style="width: 95px;"
value="keyword search"
>
<input type="hidden" name="startrow" value="0">
<input type="submit" value="Go!">
</form>
<?php

djr33
09-11-2007, 04:00 PM
And/or escape like this:
'Something abc\'def something'

Twey
09-11-2007, 04:10 PM
That's all very well for small strings, but in large or complex chunks of code it vastly detracts from readability and introduces another potential bug with every character that needs to be escaped.