Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7410227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:12:14+00:00 2026-05-29T06:12:14+00:00

Possible Duplicate: How to call a JavaScript function from PHP? I have a php

  • 0

Possible Duplicate:
How to call a JavaScript function from PHP?

I have a php page in which I echo certain things depending on the user privilege (admin or user). I would like to know if I can call a javascript function when a button is clicked.

<?php
if ($_SESSION['access_rights']=='admin') {
     $id = $_GET['id'];
     $userName = $_GET['username'];
     echo "<a href='../view/confirmDelete.php?id=$id&type=task&username=$userName'><input type='button' class='delete-btn' value=''/></a>
           <a href='../view/editTask.php?id=$id&username=$userName'><input type='submit' class='edit-btn' value=''/></a>";
}
?>

The function I would like to call is as follows. This is placed in the head of the page.

<script type="text/javascript">
function deleteTask(id,task,name) {
    var conBox = confirm("Are you sure you wanna delete task assigned to "+ name + " ?");
    if (conBox) {
        location.href="<?=$_SERVER['PHP_SELF'];?>"
    } else {
        return;
    }
}
</script>

I was wondering if the function ‘deleteTask()’ can be called via a href like

<a href="javascript" deleteTask('<?=id;?>','task','<?=userName?>');">Delete me</a>

else using onclick=”deleteTask();

I am required to pass arguments to the function. I am unable to the javascript call in href as it requires quote. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:12:14+00:00Added an answer on May 29, 2026 at 6:12 am

    With the quotes directly after javascript you close the href-attribute. Use a : to seperate the keyword javascript and the command:

    In PHP (don’t forget to escape the quotes):

    echo "<a href=\"javascript:deleteTask('$id;','task','$userName');\">Delete me</a>";
    

    or HTML:

    <a href="javascript:deleteTask('<?=$id?>','task','<?=$userName?>');">Delete me</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Call php function from javascript I understand that php is server side
Possible Duplicate: How to call a JavaScript function from PHP? Can I add a
Possible Duplicate: how can I call javascript function from another project in same solution?
Possible Duplicate: How can I call a new web page from javascript / jQuery
Possible Duplicate: Call PHP function from jQuery? Jquery on button click call php function
Possible Duplicate: Access array element from function call in php instead of doing this:
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)
Possible Duplicate: Call Python From PHP And Get Return Code probably a very stupid
Possible Duplicate: How to call another PHP script from a PHP script? I want
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.