8

Im creating a GSP form that i wish to submit using the $.ajax() call.

I understand that the GSPs get rendered into the final HTML that is seen by the browser, and thus javascript can call normal HTML elements.

my form is created as such:

<g:form action="save" id="callmeForm" >
  <fieldset class="form">
    <g:render template="form"/>
  </fieldset>
  <fieldset class="buttons">
    <g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
  </fieldset>
</g:form>

but when the final form is rendered in HTML, it lacks the id field i gave in the tag:

<form action="/racetrack/callback/save/callmeForm" method="post" >
  <fieldset class="form">
    etc...

Is there a way I can get the id property to carry thru so i can reference the form by its id with javascript?

Dave Anderson
  • 725
  • 3
  • 9
  • 17

2 Answers2

14

You can use name attribute which sets both the form tag's name and id attributes to the same value.

doelleri
  • 19,232
  • 5
  • 61
  • 65
Lauri Piispanen
  • 2,067
  • 12
  • 20
0

Since you are using ajax to post back to the server, why not just go with:

<form id="callmeForm"> 

instead?

What does using the gsp tag buy you in this case?

Or, you could try g:formRemote, which has some interesting built-in features: http://fbflex.wordpress.com/2010/05/09/adding-javascript-validation-to-formremote-ajax-forms-in-grails/