urgent - functions not working

+2 Dennis Siaw · March 5, 2015
I am writing all my javascript and jQuery functions in one .js file.

I have created a form using jquery .click() function.

The problem is that if i want to submit the form using jquery .submit() in the common .js file, it doesn't work, maybe due to the fact that the common .js file is rendered before the form is created.

How do i submit the form in the common .js file without creating a new <script></script> tag at the time of creating the form.

Post a Reply


Oldest  Newest  Rating
0 Mohamad Mirohamadi · March 5, 2015
can you put your javaScript codes here?
0 Jason Knight · March 6, 2015
If you use google chrome you can click inspect element > console and errors will be logged in the console, I recommend trying this then if your still having trouble let us know. (we all stuff up from time to time, but unless bugs can be found we my aswell be coding blindfolded)
0 Dennis Siaw · March 6, 2015
In one .php file i have:
<!-- A list of menus -->
<li id="createNew">Create New</li>
<li id="editUser">Edit User</li>

//Panel to receive responses
<div id="userPanel">

In my .js file i have:

// A request to create the form
$('#createNew').click(function() {
  $.get("user.php?createnew=user", {}, function (response) {

//Submiting the form
$('#createuserform').submit(function(e) {
      url: "user.php?action=saveuser"
      success: function(resp) {
          //verify response
   return false;

//So the problem is that the form is not submitted using the jquery above unless i open a
//script tag either above or below where i created the form before the form is submitted
//But i had wanted to avoid that

Then  i receive the request from the .js file like this in

//creating the form
if($_REQUEST['createnew']) {
   <form method="POST" action="" name="createuserform" id="createuserform">
       <label>Surname:</label><input type="text" name="username" id="username" /><br />
       <label>Firstname:</label><input type="text" name="firstname" id="firstname" /><br />

//processing the form
if($_REQUEST['action'] == 'saveuser' && $_SERVER['REQUEST_METHOD'] == 'POST') {
  //filter form inputs and save

Please your help would be deeply appreciated.
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.