i have an asp.net application in which i have to custmize the action click in submit button of a form :
the Script
<script>
$(function(){
function result(arr, identificateur,Pages) {
var f1 = $('input[name="reception' + arr + '"]').val();
var f2 = $('input[name="client' + arr + '"]').val();
var f3 = $('input[name="cloture' + arr + '"]').val();
var f4 = $('input[name="tag' + arr + '"]').val();
location = "@Url.Content("/Pages/Index")?identificateur=" + identificateur + "&Pages=" + Pages + "&_reception=" + f1 + "&_cloture=" + f3 + "&_client=" + f2 + "&_tag=" + f4;
}});
</script>
then, the form:
<input type="submit" onclick="result(@i.ToString(),@Model[1][i].Id ,"1");" value="Enregistrer"/>
When i click into the submit button, nothing is happend and i'm not redirected to the action Index
.
What are the reasons of this problem? How can i fix it?
Edit
<input type="submit" id="Enregistrer" value="Enregistrer" data-arr="@i.ToString()" data-identificateur="@Model[1][i].Id" />
<script>
$(function () {
$('#Enregistrer').click(function () {
var self = $(this); // This is the submit button
var identificateur = self.data('identificateur');
var arr = self.data('arr');
var f1 = $('input[name="reception' + arr + '"]').val();
var f2 = $('input[name="client' + arr + '"]').val();
var f3 = $('input[name="cloture' + arr + '"]').val();
var f4 = $('input[name="tag' + arr + '"]').val();
document.location.href = "@Url.Content("/Pages/Index")?identificateur=" + identificateur + "&Pages=1&_reception=" + f1 + "&_cloture=" + f3 + "&_client=" + f2 + "&_tag=" + f4;
});
});
</script>
The problems :
- the redirection didn't work
- Only in the first
tr
i can reach thejs
function
result()
function? Try addingconsole.log("IM IN RESULT()");
in theresult()
and check if it show in console. – Kamil T Oct 8 '13 at 9:49$(".className")
instead of$("#id")
. – Kamil T Oct 8 '13 at 10:54