This topic is locked

Using a javascript popup to assign a value to all selected records

12/2/2012 8:14:50 PM
PHPRunner General questions
D
DUKE author

Hi Everyone,
I have a custom button on my list page. I want to use this button to display a popup asking for user input, and then assigning the input received to a specific field of all the selected records.
This is the coding that I have on my button, but I can't get it to work:
button client:
var val=prompt("Please enter an invoice number","xxxxx");

params["invoiceno"] = $("#invoiceno").val();
button server:
global $dal;

for ($i=0; $i<count($keys); $i++)

{

$sql = "Update waybills set Invoice=".$params["invoiceno"]." where ID=" . $keys[$i]["ID"];

CustomQuery($sql);

}

$result["txt"] = "Records were updated.";
Any help will really be appreciated!

C
cgphp 12/3/2012

You are not sending the value of the promptbox to the server event of the button. Try the following block of code in the "Before client" event of the button:

var val=prompt("Please enter an invoice number","xxxxx");

if(val == null || val == "")

{

alert("Invoice number not valid");

return false;

}

params["invoiceno"] = val;


In the "Server" event of the button enter this code:

for ($i=0; $i<count($keys); $i++)

{

$sql = "Update waybills set Invoice='".$params["invoiceno"]."' where ID=" . $keys[$i]["ID"];

CustomQuery($sql);

}

$result["txt"] = "Records were updated.";