0

I want to get the value of check box selected and pass it to a query for deleting the value from database. java script code

function deleteRows(){

isTable = document.getElementById('dataTbl');
nBoxes = document.getElementsByName('delBox');
for (i=nBoxes.length-1; i>=0; i--)
{
if (nBoxes[i].checked === true)
{
var a =nBoxes[i].value;


alert("Do you want to delete this row?"+a);
isTable.deleteRow(i+1);
}
}
}

i need the var a value in perl so that i can pass it to the delete query and delete the selected row.

html code

<Table id='dataTbl' border='1' >
<tr>
<td><input type=checkbox name='delBox' value=@data></td> 
<td bgcolor=#0099FF>$pid</td>
<td bgcolor=#99CCFF>$project_name</td>
<td bgcolor=#3399FF> $variant_no</td>
<td bgcolor=#99CCFF> $variant_name</td>
<td bgcolor=#3399FF>$vehicle_class</td>
<td bgcolor=#99CCFF> $vc_no</td>
</table>
<input type=button value="Delete Rows" onclick="deleteRows()" id="delbtn">

perl query

my $sth = $dbh->prepare("delete form table name col1,col2,col3 where id='$a'"); 
$sth->execute() or die "$!";
3
  • You need to send that variable through POST or another HTTP request. Keep in mind that JS code executes in browser while Perl executes in server. And btw SQL injection incoming... Commented Apr 7, 2014 at 8:50
  • Thanks for the reply, but can you explain in more precised form. Commented Apr 7, 2014 at 9:16
  • 1
    I think it's clear enough. If you didn't understand then I suggest you read more about HTTP client/server communication, you're lacking basic concepts like POST. Commented Apr 7, 2014 at 11:36

2 Answers 2

1

You have to do POST request (or DELETE to be precise) towards server where your perl script runs.

e.g.

After you get a variable set (let's say you are using jquery):

$.ajax({
  type: "POST",
  url: url, // where your script lives
  data: {'a' : a},
  success: function(data) {
      console.log(data);
  }
  dataType: 'json'
});

in your script you will then get 'a' variable from post request.

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

Comments

0

Sample scenario:

  1. JS working on Your Client PC. Users selected some id.
  2. JS sends selected id to server side Perl CGI script.
  3. Perl parses GET request get id.
  4. Perl checks if id is number not some string to hack your server.
  5. Perl executes delete in MySQL.

Resourses: JS send GET request with Param: HTTP GET request in JavaScript?

Perl Read GET Parameter How can I read the URL parameter in a Perl CGI program?

Perl MySQL Tutorial: http://perl.about.com/od/perltutorials/a/perlmysql_3.htm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.