ckellems
asked on
syntax error using echo with Input with an onclick
This does not work:
echo '<input type="button" value="Go Home" onClick='window.location.h ref("FastD lr.php")' />';
Please provide the necessary correction and a brief discription of the solution
echo '<input type="button" value="Go Home" onClick='window.location.h
Please provide the necessary correction and a brief discription of the solution
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You use single quotes in the onclick attribute
You have to escape them
You have to escape them
echo '<input type="button" value="Go Home" onClick=\'window.location.href("FastDlr.php")\' />';
you can, but then it doesn't follow the xHTML 1.0 standard.
Just a few seconds behind.
Kudos to nplib ;-)
Kudos to nplib ;-)
ASKER
Thanks nplib, I attempted several permeations but none of them correct. What is the rule so that I may" learn how to fish" verses asking for a "fish"?
When encapsulating anything in single quotes or double quotes, if you need to use a quote in the string that is used for the encapsulation then you need to escape the quote with a \
in other words
in other words
if you make a string like this
$string = "How's it going"; //you don't need to escape anything because the quote in the string is not the same as the quote used to encapsulate the string.
if you make a string like this
$string = 'How\'s it Going"; //notice the \ to escape the single quote. without that it would error.
This same rule applies in no matter which quote you use
$string = 'This is string has a "quote" in it'; //same as the first example, the quotes in the string is not the same as the ones encapsulating the string, so they do not need to be escaped.
$string = "This is string has a \"quote\" in it"; //this time they need to be escaped with the \ other wise you will get an error.
Does this make sense?
ASKER
nplib,
Perfectly! Thanks for the fishing lesson.
Perfectly! Thanks for the fishing lesson.
echo '<input type="button" value="Go Home" onClick="window.location.h