views:

42

answers:

2

I have a page that has several ajax submission forms. Each form has a dynamic id assigned to it when it's written to the page. Does anyone know if there is an easy way to return the id of the form that is being submitted? I'm basically looking to click "submit" and alert the id of the submitted form. From there I can use it in the ajax onSuccess function.

A: 

Hmmm is there a way in cup PHP to refer to the form that is generated? In .NET you could do something like this:

$('#<%MyForm.ClientId %>')

That would return the clientside id of the form or control that is being rendered.

Achilles
+1  A: 

I suggest you retrieve it from the form in an onsubmit thingie:

<form action="/npup.do" name="foo" id="generated_4321" onsubmit="npup(this);">
[...]
</form>
<script type="text/javascript">
  function npup(form) {
    form = $(form);
    var formIdInput = new Element('input', {type:'hidden', name:'formId', value:form.id});
    form.append(formIdInput);
  }
</script>

If you just want to retrieve the form's id value on submit you just get it from the form element in the onsubmit (like above) and do whatever floats your <div> instead of shoving it into the form like I did.

npup
I actually came up with a different solution. OnClick of the submit button I'm submitting 'this' and then grabbing the form id this way:function submitThenClear( submission ){ form_id = submission.up("form").id;}
pstinnett
Ok, kinda roundabout though. In the form's onsubmit it is plain `this.id`...
npup