开发者

How to return id of a submitted form using Prototype?

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 ca开发者_开发问答n use it in the ajax onSuccess function.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜