0

I am developing a web application where you can delete users. I am using codeigniter framework to develop this. Using this code, I am invoking "Doconfirm()" function in external javascript file.

      //my view file
      <img src="<?php echo base_url(); ?>Assests/Images/cross.png" alt="Delete User"  title="Delete User" onClick="return Doconfirm()();" >

      //inside DoConfirm function javascript file
      window.location =  site_url +"user/deleteusers/id";

I want to pass id from the view to javascript doconfirm function. I know I can take the id using this php code.

      <?php echo $row['id']; ?>

What I want is to pass the id to the external javascript function "Doconfirm()" from the view. Any help will be highly appreciated.

1 Answer 1

0

You can just pass the id as a parameter in your onClick:

  //my view file
  <img src="<?php echo base_url(); ?>Assests/Images/cross.png" 
       alt="Delete User"  title="Delete User" 
       onClick="return Doconfirm(<?php echo $row['id']; ?>);" >

  //inside DoConfirm function javascript file
  function doConfirm(id) {
      window.location =  site_url +"user/deleteusers/" + id;
  }
Sign up to request clarification or add additional context in comments.

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.