[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

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
0
ckellems
Asked:
ckellems
  • 4
  • 2
  • 2
1 Solution
 
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
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now