sanitizer
sanitizer

Reputation: 105

sending multiple values through javascript

The aim of my code is to send through two values, the primary key for delete qry purposes and second value for the user confirmation window, i.e. You are about to delete the record with the registration no: E12345.

On hover of the delete button, both values are showing as should be (as shown in image below), but the delete button isnt responding, so i assume its the script section that isnt functioning right, as im unsure how to call both vals, im sure its simple but i have very basic knowledge of javascript..

The code worked as expected before i tried implementing the double value through js, originally only had 'uid'

Upvotes: 1

Views: 417

Answers (2)

dana
dana

Reputation: 18115

You should pass 2 parameters to your JS function.

Also, the reg parameter looks to be a string a should be quoted.

JS:

function delete_user(uid, reg) {
    if (confirm('Please confirm whether to delete the vehicle record with the Registration Number: ' + reg)) {
        window.location.href = '../php/clerk-delete.php?id=' + uid; 
    }
}

PHP:

echo '<a href="javascript:delete_user('.$get_info['VehicleId']. ','.htmlentities(json_encode($get_info['VehicleRegNo'])).')">&nbsp;Delete&nbsp;</a>'

Upvotes: 3

D.M.
D.M.

Reputation: 7

if you just change the + with , it works:

function delete_user(uid,reg) {
  if (confirm('Please confirm whether to delete the vehicle record with the       Registration Number: ' + reg)){
  window.location.href = '../php/clerk-delete.php?id=' + uid; 
  }
}

and then

echo '<a href="javascript:delete_user('.$get_info['VehicleId']. ','.$get_info['VehicleRegNo']. ')">&nbspDelete&nbsp</a>'

Upvotes: 0

Related Questions