CodeIgniter Forums
Help please my javascript is not working in CI.. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Help please my javascript is not working in CI.. (/thread-51385.html)

Pages: 1 2


Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]kit005[/eluser]
I'm a newbie in codeigniter, my problem is the javascript it doesnt work in Ci though my css goes well in it.. I just cant find my mistake.. Hope somebody can help me.. I appreciate it so much..

My home page
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> &lt;html&gt; &lt;head&gt; &lt;base href="&lt;?php echo base_url();?&gt;" /&gt; &lt;title&gt;My Page&lt;/title&gt; &lt;meta http-equiv="Content-Language" content="English" /&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
[removed][removed]
[removed][removed]
[removed][removed]
[removed][removed]
[removed][removed]
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url();?&gt;css/stylered.css" media="screen" /&gt;
&lt;link rel="stylesheet" type="text/css" href="&lt;?php echo base_url();?&gt;button.css" media="screen" /&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="centered">
<div id="wrap">
<div id="header">
    <img src="/demo/images/headerred.jpg" width="82%" heigth="20%" />
</div>
<div id="top"> </div>
<div id="content">
<div>
<div id="box">
<br /><br />
<br /><br />
<br /><br />
       <table width="420">
           &lt;form method="GET" id="myform" name="myform"&gt;
            <tr>&lt;?php echo form_open('educ/view2'); ?&gt;
              <td width="420" height="15" align="center">
               <p>
               &lt;input type="text" id="contractno "name="contractno" maxlength="7" size="25" class="form" autofocus="autofocus"/&gt;
               </p>
              </td>
            </tr>
       </table>
       <br />
       <div>
       <table id="table">
            <tr>
               <td width="413" height="35" align="center">
               &lt;input name="submit" id="submit" type="image" src="&lt;?php echo base_url();?&gt;images/submit2red.png" width="30%" heigth="15%" value="submit" /&gt;
               &lt;?php echo form_close(); ?&gt;
               </td>
            </tr>
            &lt;/form&gt;
       </table>
       </div>
    </div>
</div>
<div>
</div>
</div>
<div id="bottom">
</div>
<div id="footer">
</div>
</div>
&lt;/body&gt;
&lt;/html&gt;


My root derictory
+system
+application
-views
-index
-view2
-display
-display2
-controller
+index
+js
-function
-jquery
-js_lib
-soon
+css
-style.css
-stylerd.css


My problem is, when the user inputs it doesnt fetch the data and direct to the other page, it remain just in that page..

My controller

Code:
&lt;?php
class educ extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->helper(array('form', 'url'));
  $this->load->library('javascript');
  $this->load->model('educ_model');
}
public function index()
{
  $data['library_src'] = $this->jquery->script();
                $data['script_head'] = $this->jquery->_compile();
  $this->load->view('educ/index');
  
  /*if(count($queryr['details'])==0)
  {
   echo "[removed]alert('Enter Contract Number');[removed]";
  }*/
  
}

public function view2()
{
  session_start();
  $_SESSION['contractno'] = $_REQUEST['contractno'];
  $queryr['details'] = $this->educ_model->educplan($_SESSION['contractno']);
  
  if(count($queryr['details'])>0)
  {
   $this->load->view('educ/view2', $queryr);
  }
  
  
  else {
   echo "[removed]alert('No Record found');[removed]";
   $this->load->view('educ/index');
  }
  
  
  
}

public function display()
{
  session_start();
  $cno = $_SESSION['contractno'];
  /*$_SESSION['sname'] = $_REQUEST['sname'];
  $_SESSION['fname'] = $_REQUEST['fname'];
  $_SESSION['mi'] = $_REQUEST['mi'];
  $_SESSION['dob'] = $_REQUEST['dob'];
  $_SESSION['contractdate'] = $_REQUEST['contractdate'];*/
  
  $queryr['details'] = $this->educ_model->educplan($cno);
  $this->load->view('educ/display', $queryr);
}

public function display2()
{
  session_start();
  $cno = $_SESSION['contractno'];
  
  $_SESSION['neweadd'] = $_REQUEST['eadd'];
  $_SESSION['newcpnum'] = $_REQUEST['cpnum'];
  $_SESSION['newcpprefix'] = $_REQUEST['cpprefix'];
  
  $queryr['details'] = $this->educ_model->educplan($cno);
  $queryr['beneficiary'] = $this->educ_model->beneficiary($cno);
  //print_r($queryr);
  $this->load->view('educ/display2', $queryr, $_SESSION);
}

public function save()
{
  session_start();
  $cntno = $_SESSION['contractno'];
  $educdata = array(
                        
                        'cpprefix' => $_SESSION['newcpprefix'],
                        'cpnum' => $_SESSION['newcpnum'],
                        'eadd' => $_SESSION['neweadd']
                        );
  //print_r($educdata);
  $this->educ_model->savechanges($educdata,$cntno);
  echo "[removed]alert('DATA UPDATED!!!');[removed]";
  $this->load->view('educ/cert');
  
}
}

It works well in php but when i transfer it in CI i got a hard time.. :down:


Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]kit005[/eluser]
My the removed code is my link to the javascript it goes like this..

[removed][removed]..Smile


Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]InsiteFX[/eluser]
To post javascript code you need to replace the s in the script tags with a $ then it will post.
Code:
<$cript>

</$cript>

Because that is what we need to see is your javascript code.



Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]kit005[/eluser]
<$cript language="javascript" src="&lt;?php echo base_url();?&gt;js/function1.js"></$cript>
<$cript language="javascript" src="&lt;?php echo base_url();?&gt;js/function.js"></$cript>
<$cript language="javascript" src="&lt;?php echo base_url();?&gt;js/checkform3.js"></$cript>
<$cript language="javascript" src="&lt;?php echo base_url();?&gt;js/jquery.js"></$cript> //this is my library.
<$cript language="javascript" src="&lt;?php echo base_url();?&gt;js/js_lib.js"></$cript> //this is my library.

Heres my removed code. tnxSmile


Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]InsiteFX[/eluser]
Well your problem is in one of your javascript files were it is not seeing the correct paths to your controller!

You can do this and have access to both base_url() and site_url()
Code:
&lt;head&gt;
// replace $ with s in script tags!
<$cript type="text/javascript" charset="utf-8">
  //&lt;![CDATA[
   var base_url = "&lt;?php echo base_url(); ?&gt;";
   var site_url = "&lt;?php echo site_url(); ?&gt;";
  // ]]>
</$cript>
&lt;/head&gt;

Now you can use base_url and site_url in your javacript files like this:
Code:
url: base_url+"path_to_controller";



Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]kit005[/eluser]
Thank you ill try it in my codes.. Hope it'll work fine, so simple yet so hard..^_^


Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]InsiteFX[/eluser]
Most of the time when javascript doe's not work it is because of the paths.



Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]kit005[/eluser]
I still get the same result..Undecided


Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]InsiteFX[/eluser]
Try changing this:
Code:
// form this.
&lt;form method="GET" id="myform" name="myform"&gt;

// to this.
&lt;form method="POST" id="myform" name="myform"&gt;



Help please my javascript is not working in CI.. - El Forum - 05-02-2012

[eluser]ojcarga[/eluser]
Also look this:

Code:
&lt;form method="GET" id="myform" name="myform"&gt;
<tr>&lt;?php echo form_open('educ/view2'); ?&gt;

It seems you are opening the form twice.

And closing it twice too

Code:
&lt;?php echo form_close(); ?&gt;
               </td>
            </tr>
            &lt;/form&gt;