简体   繁体   中英

Error: Expected expression, got end of script

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???

在此处输入图片说明

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.

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.

I think you are looking for something like this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM