0

When clicking on the "Print Ticket" button Javascript is throwing an syntax error in firebug indicating "Expected expression, got end of script" However this is a straight forward bit of php/javascript code so i'm at a loss for the syntax problem. This button is not addressed by any Jquery function and I don't see any conflicting single/double quotes???

enter image description here

echo "<div style='height:550px; width:900px;' id='btarget'><div id='tcontrol'>"; if ($var1v!=="Paid" && $_SESSION['tickstatus']!=="Closed,Complete") {echo "<input name='reschtick' id='reschtick' type='button' value='RESCHEDULE' /><input name='closetick' id='closetick' type='button' value='CLOSE TICKET' />";} echo $varv1; echo '<input type="button" value="PRINT TICKET" onclick="http://www.thetargetdomain.com/ops/includes/pdfconveview.php?dispinv='.$_GET[vtick].'&action=eview" />'; echo "</div> 

If I view this in source i get:

<input type="button" onclick="http://www.thetargetdomain.com/ops/includes/pdfconveview.php?dispinv=06151205&amp;action=eview" value="PRINT TICKET"> 

if I enter in the SRC url as shown above directly into the browser it works fine. It just has some issue with triggering from the button click.

3
  • 3
    I don't think you understand what onclick does Commented Jun 22, 2015 at 17:10
  • Assigning an URL to the onclick attribute does not work. Perhaps you want to use an <a> tag and assign an URL to the href attribute? The onclick attribute expects Javascript code. Commented Jun 22, 2015 at 17:15
  • @AndreiNemes no i get what onclick does, just got a cross eyed in the code and forgot the obvious. the window.location being left out was just an oversight on my part and it shouldn't have happened. Commented Jun 22, 2015 at 17:19

3 Answers 3

2

That makes no sense. You are assigning a URL to a onclick, that is wrong.

If you want to go to a page, you need to set the window location or wrap the button in an anchor.

onclick="window.location.href='http://www.example.com';" 

Using inline events is bad practice.

Sign up to request clarification or add additional context in comments.

3 Comments

Well.... ok, call me temporarily stupid for missing the obvious. Too many lines of code today and just overlooked something I shouldn't have. Thanks for pointing out the obvious. - The use of inline is to fix a short term problem in old code while a whole new backend is being built... bandaid programming
@DMSJax Nowhere did he call you stupid. I think you are taking this too personal. If you didn't need his help then you shouldn't have posted here in the first place. This site works because we can cut straight to the issue and skip the sugar coating
@AndreiNemes Your misunderstanding my statement. It was self criticism. Not accusatory about him.
0

I think you are looking for something like this:

<form action="http://google.com"> <input type="submit" value="Google"> </form> 

Comments

0

For this situation, it is better to use an anchor tag.

onclick is used to run JavaScript when that element is clicked. Since you are only redirecting the page, it is easier to use an anchor.

<a href="http://www.thetargetdomain.com/ops/includes/pdfconveview.php?dispinv=<?=$_GET[vtick]?>&action=eview" value="PRINT TICKET" /><?=$varv1?></a> 

If, for some reason, you absolutely need it to be an input, then you have to use window.location:

<input type="button" value="PRINT TICKET" onclick="window.location.href='http://www.thetargetdomain.com/ops/includes/pdfconveview.php?dispinv=<?=$_GET[vtick]?>&action=eview';" /> 

Here is a link to the MDN documentation for window.location: https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.