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.

2
  • where you are passing the parameters ? Commented May 1, 2015 at 12:02
  • <a class="btn btn-success" onclick ="go('clase')">Volver</a>' Commented May 1, 2015 at 12:03

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

Comments

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

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.