Ok I got it finally. I managed to get it with bind submit but it was firing
off multiple times after each save click so first save would send 1 request,
second fired 2 and so on....so this is what I ended up with.
Page JS:
<script type="text/javascript">
$("form").bind("submit", function() {
var $this = $(this);
var form_id = $this.closest('form').attr("id");
uRec('#' + form_id);
return false;
});
</script>
Eternal JS:
function uRec(selector){
$form.unbind("submit");//prevent repreated submits
var data = $(selector).formSerialize();
var form_url = $(selector).attr('action');
var form_target = form_url.substr(1).replace( new RegExp( "/" ,"g"),
"_" );
var update_target = (form_target.replace("_edit", ""));
alert(form_url + form_target + update_target);
$.blockUI({ message: null});
$(selector).ajaxSubmit({
type: "post",
url: form_url +'/',
data: data,
dataType: 'json',
success: function(response){
if (response.status === true)
{
$.unblockUI();
$('#' +
update_target).html(response.html).slideToggle('slow').highlightFade({speed:
2000});
$('#' +
form_target).slideToggle('slow');
} else {
$.unblockUI();
$('#' + form_target).html(response.html);
}
}
});
return false;
};
If anyone could glace over the code to see if there is anything that looks
wrong or could use improvement please let me know.
Thanks again for all your time
Dave
-----Original Message-----
From: Jack Killpatrick [mailto:[email protected]]
Sent: January-16-10 7:51 PM
To: [email protected]
Subject: Re: [jQuery] Complicated Question
If you're rendering the button on-the-fly (as part of your form) be sure to
either a) hook up that button click handler after the button is rendered or
b) use the event delegation approach I showed in my example.
It sounds like your click is not firing now, probably because the click
isn't actually getting bound to the button.
- Jack
Dave Maharaj :: WidePixels.com wrote:
> I have completely removed the uRec function for now and changed to a
> regular button, no submit.
>
> <input type="button" value="Button"/>
> </form>
>
> <script type="text/javascript">
>
>
> $("button").click(function () {
> var form_id = '#123123123';
> //var form_id = $this.closest('form'); // get the recordId
>
> alert(form_id);
> //uRec(form_id);
> return false;
>
> //or return false; both do nothing
> })
>
>
> </script>
>
> But not even an alert now. Man ohh man
>
> Thanks again for your ideas.
>
> Dave
>
>
>
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.725 / Virus Database: 270.14.139/2620 - Release Date: 01/16/10
04:05:00