Sunday, 29 September 2013

Jquery Form plugin : dynamic target/multiple forms

Jquery Form plugin : dynamic target/multiple forms

I am using the form plugin from http://malsup.com/jquery/form/
I am trying to set the target div to be updated dynamically. At the moment
this is what the code looks like but instead I want to pas a different
value for target through a hidden form field, so the #target2 can be
dynamically changed to #target20, #target40 etc. Thanks.
<script type="text/javascript">
$(document).ready(function() {
$('.htmlForm').ajaxForm({
target: '#target2',
success: function() {
$('#target2').fadeIn('slow');
}
});
});
</script>
and the form html
<form class="htmlForm" action="ajax-data.php" method="post">
<input type="hidden" name="target" value="ztest" />
Message: <input type="text" name="message" value="Hello HTML" />
<input type="submit" value="Echo as HTML" />
</form>
and the div to be updated
<div id="ztest"></div>
another form
<form class="htmlForm" action="ajax-data.php" method="post">
<input type="hidden" name="target" value="ztest2" />
Message: <input type="text" name="message" value="Hello HTML" />
<input type="submit" value="Echo as HTML" />
</form>
and another div to be updated
<div id="ztest2"></div>

No comments:

Post a Comment