1

If I try to pass a parameter to a function in the onclick event it doesn't work, clase is to access to clase/index method from a codeigniter controller.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Bootstrap -->
        <link href="<?php echo base_url('bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="<?php echo base_url('bootstrap/js/bootstrap.min.js');?>"></script>
        <script language='javascript' type='text/javascript' src="<?php echo base_url('js/action.js');?>"></script>

    </head>
    <body>   
        <div class='container'>
            <h1>Esta página es solo accesible para el administrador.</h1>
             <a class="btn btn-success" onclick ="go('clase')">Volver</a>'
        </div>
    </body>
</html>

And this is the function

function go(url){
    //var url = "clase";    
    $(location).attr('href',url);
}

Without the parameter it works. But if I pass the parameter, nothing happens.

Shehary
  • 9,926
  • 10
  • 42
  • 71
AFS
  • 1,433
  • 6
  • 28
  • 52

2 Answers2

2

This works for me:

<script type="text/javascript">
function go(url){  
    $(location).attr('href',url);
}
</script>

<a href="javascript:void(0);" class="btn btn-success" onclick="go('clase')">Volver</a>
Community
  • 1
  • 1
Jordy
  • 4,719
  • 11
  • 47
  • 81
2

remove last comma from your anchor tag and add href to anchor tag

<a href="#" class="btn btn-success" onclick ="go('clase')">Volver</a>

and make sure your go() inside script tag

Saty
  • 22,443
  • 7
  • 33
  • 51