Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7879139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:50:07+00:00 2026-06-03T03:50:07+00:00

I currently have a button when clicked it should open up a new window

  • 0

I currently have a button when clicked it should open up a new window but I am getting this error: Uncaught SyntaxError: Unexpected token :. I am using window.open()

$url = "http://www.google.com";
$button .= 
'<input type="button" value="Print Timetable" class="printButton" onclick="window.open('.$url.');"/>';

I have noticed that when I use window.open() with no parameters it works but when I pass in the $url variable all hell breaks loose. I get syntax errors. I’ve tried http://www.google.com, http://www.google.com and google.com to no avail!

Thanks for your help in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:50:08+00:00Added an answer on June 3, 2026 at 3:50 am

    Because you are missing the single quotes needed to encapsulate the url string.

    $url = "http://www.google.com";
    $button .= 
    '<input type="button" value="Print Timetable" class="printButton" onclick="window.open(\''.$url.'\');"/>';
    

    You’re adding a layer of string encapsulation. When you pass a string value to a function it must be in quotes, as it is a string.

    doSomething('http://www.ibm.com/');
    

    When you are doing this inline in your html, you need to encapsulate the javascript in double quotes so it becomes

    onclick="doSomething('http://www.ibm.com/');"; 
    

    Then, if you want PHP to echo that, or to assign it as variable, you need to enclose all of that in quotes, so you can do

    <?php 
        //encapsulate in double quotes and escape double quotes
        echo " onclick=\"doSomething('http://www.ibm.com/');\" "; 
    
        //encapsulate in single quotes and escape single quotes
        echo ' onclick="doSomething(\'http://www.ibm.com/\'); '; 
     ?>  
    

    Any way you break it down you need have 3 string encapsulations embedded in one another, so you must find a way to differentiate between the quotes used in JS and the quotes used in PHP.

    Otherwise you would have a problem.

    <?php 
    
        //Houston We have a problem!
        echo " onclick="doSomething('http://www.ibm.com/');\" "; 
             ^         ^                                    ^ ^
     Open Quote       Close Quote                  Open Quote Close Quote 
     ?>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a simple form that when you click the save button will
I currently have my code set to disable the submit button when the field
I currently have some code which when you press the submit button, a marker
Currently, I have some basic code to play a simple tone whenever a button
Currently I have an Array that is having 9 buttons pushed to it. This
I have this button which is not working correctly for hold button for a
I currently have this data in a sheet Col A Col B 1 angry
I have a simple ASP.Net login page. When the login button is clicked, the
Currently I have a set of fields on a page. When the button is
I'm new to Android stuff. Currently I have someone else code in my hand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.