Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Form is not defined" error using jQuery
    primarykey
    data
    text
    <p>I am learning jquery and am writing some very simple jquery code that posts some variables to a method in my controller. I get “myform is not defined” error in firebug when using the code posted below.</p> <p>Here is my html:</p> <pre><code>&lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;script type="text/javascript" src="assets/js/jquery-1.7.1.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function get(){ $.post('jqtest/test',{name: myform.myname.value}, function (output){ $('#username').html(output).show(); } ); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt;TODO write content&lt;/div&gt; &lt;form name="myform"&gt; &lt;input type="text" name="myname"&gt; &lt;input type="button" value="Get" onclick="get();"&gt; &lt;/form&gt; &lt;div id="username"&gt;&lt;/div&gt; &lt;/body&gt; </code></pre> <p>Here is my codeigniter controller code:</p> <pre><code>class Jqtest extends CI_Controller { function _Jqtest() { parent::controller(); } function index() { $this-&gt;load-&gt;view("jqtest/jqtest.html"); } function test() { print_r($_POST); $this-&gt;load-&gt;view("jqtest/jqtest.html"); } } </code></pre> <p>When the Get button is clicked, the test method should print the POST values. When I run the code in FireFox, it's not working (nothing is getting printed out). When I checked the firebug console, I found a "myform is not defined" error.</p> <p>I know there is something wrong with my jQuery get() function, can anybody please help me out, thank you very much!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload