moleeee
moleeee

Reputation: 37

Unable to pass multiple parameters in onclick php

I am trying to pass multiple parameters in an onclick with variables, although coming up with an error of

  • Uncaught SyntaxError: missing ) after argument list.

The error is on this line

echo'<a onclick="changebill('.$myrow['address_ID'].', '.$myrow['address_1'].', '.$myrow['address_2'].');"> ';

Upvotes: 0

Views: 180

Answers (2)

Hasnain Ashfaq
Hasnain Ashfaq

Reputation: 41

Try using double quotes. Use \" for every time you have to use double quotes anywhere.

echo "<a onclick=\"changebill( " . $myrow['address_ID'] . " , " . $myrow['address_1'] . " , " . $myrow['address_2']  . ") \">";

Upvotes: 0

Muhammad Omer Aslam
Muhammad Omer Aslam

Reputation: 23738

Change it to the following if the anchor is inside the echo statement

echo  '<a onclick="changebill(\''.$myrow['address_ID'].'\', \''.$myrow['address_1'].'\', \''.$myrow['address_2'].'\');"> ';

You have to add the quotes around the parameters as the text you are sending might contain spaces and break. Your code will output it like below

<a onclick="changebill(1, my house address, my street number);"> 

whereas it should be like

<a onclick="changebill('1', 'my house address', 'my street number');"> 

Upvotes: 1

Related Questions