title: Javascript in Controller Codeigniter
body: <p>Is it possible to have a javascript code in the controller? I'm trying to have an alert if the login failed, </p>
  
  <p>here is the condition in my controller:</p>
  
  <pre><code>public function login2()
  {
      if(!empty($_POST['btn_login'])){
          $session_login = $this-&gt;inventory_model-&gt;select_login($this-&gt;input-&gt;post());
          if($session_login){
              $this-&gt;session-&gt;set_userdata('login_session', 
                  array(
                      'Username' =&gt; $session_login-&gt;Username,
                      'Password' =&gt; $session_login-&gt;Password,
                      'UserType' =&gt; $session_login-&gt;UserType
                  )
              );
              redirect('inventorysys_controller/homepage');
          }
          else{
              echo "Invalid Username/Password!";
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to put the javascript in the else, so is it possible guys?</p>
  
  <p>Here is my view in case you need a reference:</p>
  
  <pre><code>&lt;form action="login2" method="POST" id="log_form" name="log_form" style="margin-left: auto; margin-right: auto;"&gt;
      &lt;div class="modal-body"&gt;
         &lt;div class="container"&gt;     
            &lt;div id="nav_log1"&gt;
              Username: &lt;input type="text" id="txt_user1" name="txt_user1" style="color: black;"/&gt;
              Password: &lt;input type="password" id="txt_pass1" name="txt_pass1" style="color: black;"/&gt;
            &lt;/div&gt;
          &lt;/div&gt; &lt;!-- /container --&gt;
      &lt;div class="modal-footer" style="padding: 20px; margin-top: 20px;"&gt;
          &lt;button type="submit" value="login" id="btn_login" class="btn btn-primary btn-sm" name="btn_login"&gt;Sign-In&lt;/button&gt;
          &lt;button class="btn btn-warning btn-sm" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
          &lt;!--&lt;button id="close_me" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;--&gt;
      &lt;/div&gt;
      &lt;/div&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>Your help will be truly appreciated. :)</p>