syntax error using echo with Input with an onclick

This does not work:
echo '<input type="button" value="Go Home" onClick='window.location.href("FastDlr.php")' />';
Please provide the necessary correction and a brief discription of the solution
ckellemsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nplibCommented:
make it like this

echo '<input type="button" value="Go Home" onClick="window.location.href(\'FastDlr.php'\)" />';
0
nplibCommented:
oops

put the second slash on the wrong side.
echo '<input type="button" value="Go Home" onClick="window.location.href(\'FastDlr.php\')" />';

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Albert Van HalenAnalyst developerCommented:
You use single quotes in the onclick attribute
You have to escape them
echo '<input type="button" value="Go Home" onClick=\'window.location.href("FastDlr.php")\' />';

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

nplibCommented:
you can, but then it doesn't follow the xHTML 1.0 standard.
0
Albert Van HalenAnalyst developerCommented:
Just a few seconds behind.

Kudos to nplib ;-)
0
ckellemsAuthor Commented:
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"?  
0
nplibCommented:
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
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?

Open in new window

0
ckellemsAuthor Commented:
nplib,
Perfectly!  Thanks for the fishing lesson.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.