Aleks
asked on
jquery submit form
I am trying to submit a form inside a modal window using jquery.
the form tag is:
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" name= "form2">
I am using this script but the problem is that the form submits on load of the page instead of when I click the 'submit' button
<button type="submit" class="btn btn-primary" >Save changes</button>
and the script:
<script>
$('#edit-modal').on('show. bs.modal', function(e) {
var $modal = $(this),
esseyId = e.relatedTarget.id;
$modal.find('.edit-content ').html(es seyId);
})
$("form[name='form2']").su bmit()
</script>
the form tag is:
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" name= "form2">
I am using this script but the problem is that the form submits on load of the page instead of when I click the 'submit' button
<button type="submit" class="btn btn-primary" >Save changes</button>
and the script:
<script>
$('#edit-modal').on('show.
var $modal = $(this),
esseyId = e.relatedTarget.id;
$modal.find('.edit-content
})
$("form[name='form2']").su
</script>
ASKER
Julian,
I am not familiar with jquery I am trying to figure things out still.
If I want the button to do the submit how would I change this code ?
--
$(function() {
// ON LOAD FUNCTIONALITY HERE
...
// SET UP EVENT HANDLER
$('SOME_SELECTOR').click(f unction(e) {
e.preventDefault();
// INSIDE EVENT HANDLER
// NOT IN ON LOAD
$('form[name="form2"]').su bmit();
});
});
--
button:
<button type="submit" class="btn btn-primary" >Save changes</button>
Do I need to add code to the button ?
I am not familiar with jquery I am trying to figure things out still.
If I want the button to do the submit how would I change this code ?
--
$(function() {
// ON LOAD FUNCTIONALITY HERE
...
// SET UP EVENT HANDLER
$('SOME_SELECTOR').click(f
e.preventDefault();
// INSIDE EVENT HANDLER
// NOT IN ON LOAD
$('form[name="form2"]').su
});
});
--
button:
<button type="submit" class="btn btn-primary" >Save changes</button>
Do I need to add code to the button ?
ASKER
I tried the following:
Form:
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" form="form2"></form>
Submit button:
<button type="submit" class="btn btn-primary" id = "mdlsave" >Save changes</button>
Script (from you)
<script>
$('#edit-modal').on('show. bs.modal', function(e) {
var $modal = $(this),
esseyId = e.relatedTarget.id;
$modal.find('.edit-content ').html(es seyId);
})
$(function() {
// ON LOAD FUNCTIONALITY HERE
// SET UP EVENT HANDLER
$('mdlsave').click(functio n(e) {
e.preventDefault();
// INSIDE EVENT HANDLER
// NOT IN ON LOAD
$('form[name="form2"]').su bmit();
});
});
</script>
But still won't submit the form :#
Form:
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" form="form2"></form>
Submit button:
<button type="submit" class="btn btn-primary" id = "mdlsave" >Save changes</button>
Script (from you)
<script>
$('#edit-modal').on('show.
var $modal = $(this),
esseyId = e.relatedTarget.id;
$modal.find('.edit-content
})
$(function() {
// ON LOAD FUNCTIONALITY HERE
// SET UP EVENT HANDLER
$('mdlsave').click(functio
e.preventDefault();
// INSIDE EVENT HANDLER
// NOT IN ON LOAD
$('form[name="form2"]').su
});
});
</script>
But still won't submit the form :#
I am confused though - why do you need jquery to make a button submit? Form buttons by default submit the form - so why do you need JQuery to do it?
ASKER
I have a normal submit button. Above is the code.
ASKER
This is to submit the form:
<button type="submit" class="btn btn-primary" id = "mdlsave" name = "mdlsave" >Save changes</button>
And this is the code you sent with the selector with the name 'mdlsave'
$(function() {
// ON LOAD FUNCTIONALITY HERE
...
// SET UP EVENT HANDLER
$('mdlsave').click(functio n(e) {
e.preventDefault();
// INSIDE EVENT HANDLER
// NOT IN ON LOAD
$('form[name="form2"]').su bmit();
});
});
But the form still not submitting. I tried without the code and just use a simple form and the submit button but for some reason it won't submit.
<button type="submit" class="btn btn-primary" id = "mdlsave" name = "mdlsave" >Save changes</button>
And this is the code you sent with the selector with the name 'mdlsave'
$(function() {
// ON LOAD FUNCTIONALITY HERE
...
// SET UP EVENT HANDLER
$('mdlsave').click(functio
e.preventDefault();
// INSIDE EVENT HANDLER
// NOT IN ON LOAD
$('form[name="form2"]').su
});
});
But the form still not submitting. I tried without the code and just use a simple form and the submit button but for some reason it won't submit.
That is probably because of the errors in your markup.
You have two <form> declarations both of which terminate on the same line they are declared.
You need to fix those. Please refer to the sample
http://www.marcorpsa.com/ee/t962.html
You have two <form> declarations both of which terminate on the same line they are declared.
You need to fix those. Please refer to the sample
http://www.marcorpsa.com/ee/t962.html
To clarify
You need to put your controls between the <form> tags
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" form="form2"></form>
You need to put your controls between the <form> tags
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" form="form2">
PUT YOUR FORM FIELDS HERE - NOT OUTSIDE
</form>
ASKER
Yes of course. Here is my whole form code:
--
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" form="form2"></form>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h3 class="modal-title">Edit form</h3><small>Please select the Beneficiary that will fill out the form and update the description.</small>
</div>
<div class="panel-body">
<div >
<div class="ibox float-e-margins">
<div class="form-group"><label class="col-sm-2 control-label">Beneficiary </label>
<div class="col-sm-10">
<select class="form-control m-b" name="account">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
</select>
</div> </div>
<div class="form-group"><label class="col-sm-2 control-label">Description </label>
<div class="col-sm-10"><input id = "idfield" name "idfield" type="text" class="form-control" placeholder="Mr. | Ms." value="<%=request("formcas eid")%>">< /div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close </button>
<button type="submit" class="btn btn-primary" id = "mdlsave" name = "mdlsave" >Save changes</button>
</div>
</div>
</form>
----
--
<form action="forms_SPedit.asp" method="post" class="form-horizontal" id="form2" form="form2"></form>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
<h3 class="modal-title">Edit form</h3><small>Please select the Beneficiary that will fill out the form and update the description.</small>
</div>
<div class="panel-body">
<div >
<div class="ibox float-e-margins">
<div class="form-group"><label class="col-sm-2 control-label">Beneficiary
<div class="col-sm-10">
<select class="form-control m-b" name="account">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
</select>
</div> </div>
<div class="form-group"><label class="col-sm-2 control-label">Description
<div class="col-sm-10"><input id = "idfield" name "idfield" type="text" class="form-control" placeholder="Mr. | Ms." value="<%=request("formcas
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close
<button type="submit" class="btn btn-primary" id = "mdlsave" name = "mdlsave" >Save changes</button>
</div>
</div>
</form>
----
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Seems to me there was an extra tag there because the form was closed at the bottom .. let me delete it and try ..
ASKER
Ok cool ! .. the form submits. I will close this ticket and concentrate on passing the value to the form.
ASKER
Thanks for the patience :#
You are welcome.
Open in new window
But now I am confused - you want to use jquery to submit the form when you press the submit button ... Why? Why not just let the submit button do what it is supposed to do?
To submit a form on an event you need to do something like this
Open in new window