2

I have a form and here's the handler for the submit button:

$( '#submit_btn' ).click( function( data ){ 
    theForm = document.getElementById( 'realForm' );
    theForm.meetingName.value = document.getElementById( 'meeting_name' ).value;
    theForm.meetingId.value = '';
    theForm.description.value = document.getElementById( 'mtg_description' ).value;
    theForm.startTime.value = startDate + ' ' + startTime;
    theForm.endTime.value = endDate + ' ' + endTime;
    theForm.loginName.value = participants;
    theForm.role.value = roles;
    theForm.docRights.value = docRights;
    theForm.submit();
});

This handler basically pre-processes some data and sends to a hidden form, this:

<form id="realForm" style="visibility:hidden" action="/app/meeting/create" method="post">
    <input name="loginName" type="text">
    <input name="meetingName" type="text">
    <input name="meetingId" type="text">
    <input name="startTime" type="text">
    <input name="endTime" type="text">
    <input name="description" type="text">
    <input name="roles" type="text">
    <input name="docRights" type="text">
</form>

Problem is that the request isn't hitting the endpoint defined in the hidden form. What am I doing wrong here?

I've changed to make the input types hidden instead of the form. The submit handler certainly executes and, using FireBug, I don't see the request going out under the NET tab.

I'm using this dummy data to try and trigger the request but it's still not working:

theForm.meetingName.value       = "MY MTG";
                        theForm.meetingId.value         = '';
                        theForm.description.value       = "DESC";
                        theForm.startTime.value         = "2013-05-25 00:00:00";
                        theForm.endTime.value           = "2013-05-25 02:00:00";
                        theForm.loginName.value         = "foo@frr.com";
                        theForm.role.value              = "M,M";
                        theForm.docRights.value         = "CRUT,CRUT";
4

4 回答 4

2

2 tips:

  1. use this for fetching variable from input.

    $("#NAME_OF_YOUR_INPUT_ID").val(); 
    
  2. use hidden input instead and identify each one with ID.

    <input id="docRights" type="hidden">
    
于 2013-05-24T19:06:06.517 回答
1

I'd try this out:

document.forms.realForm.submit()
于 2013-05-24T19:05:39.680 回答
1

你的input名字roles不是role

将您的 JS 行更改为:

theForm.roles.value = roles;

见 JS 小提琴:http: //jsfiddle.net/jav6s/

于 2013-05-24T19:14:38.077 回答
1

问题是我的第一个表单有一个 type = "submit" 的按钮......所以即使我不希望它提交表单也是如此。

我不得不将类型更改为“按钮”以防止这种情况发生。

感谢所有及时的回复。

于 2013-05-24T19:36:57.010 回答