Cant take function argument

cant take function argument in a variable name mytext

html code is below

<a id="tod" href="" onclick="today(a)" ><i class="fa fa-calendar"></i>{{this.tod}}</a>

javascript code is below

$(document).ready(function today(a){
        var mytext = a;
        $('#tod').click(function(event){

        event.preventDefault();
        
    $.ajax({
        url:"/ajaxdemo",
        data:{text:mytext},
        method:"POST",
        success: function(res){
            alert(res.from)
        },
        error: function(err){
            console.log(err)
        }
    
    })
})
})

I got the solution

I edited html code to

<a  href="javascript:today('{{this.tod}}')"  ><i class="fa fa-calendar"></i>{{this.tod}}</a>

edited javascript code to


     function today(tod){
    $.ajax({
        url:"/ajaxdemo",
        data:{text:tod},
        method:"POST",
        success: function(res){
            alert(res.from)
        },
        error: function(err){
            console.log(err)
        }
    
    });
    return false;
     }
    

Could you explain your problem a little more? it’s too vague.

another thing I have noticed is that you have a today(a) function call assigned to the onClick event in your html. and then you assign another function in your js causing a complication because today will run first but it is undefined. This prevents your intended js function from running