Jump to content

onclick submit and return false


thewooleymammoth

Recommended Posts

Although my script is using ajax, my problem is in the javascript

 

Im using an editor that formats text called openwysiwyg, and im using ajax to write the content of the editor to a file. So i need to get the value of the textarea. the problem is, the editor must be showing the text the user types in a different feild, then when the form is submitted, inserts teh text into the feild. So what i need to do is do and onclick='$('textarea').submit();' and then return it false so that the form doesnt actually change. Ex:

<html>
  <head>
  <script type='text/javascript'>
  function get_value()
  {
    var val =$('ta').value
  }

  </script>
  </head>
  <body>
   <form onSubmit='return false;'>
     <textarea id='ta'></textarea>
     <button onclick='$('ta').submit(); get_value();'>update</button>
   </form>
  </body>
</html>

 

however the above code doesnt seem to work, the form still submits. if anyone could help me find a way to do this, it would be most appreciated, thanks. Im using prototype btw. and here is a link to a demo of openwysiwyg    http://www.openwebware.com/wysiwyg/demo.shtml

Link to comment
Share on other sites

When a form submits when you have a return false to prevent it from doing so, that typically points to a javascript error that is occurring - which prevents the return false from triggering.

 

In this case I see at least one problem on the button object. You are defining the onclick function within single parens, but then you have parameters inside the onclick trigger action that also has single parens. Once the processor hits the 2nd single paren it thinks that is the end of the trigger code. Try this

<button onclick="$('ta').submit(); get_value();">update</button>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.