[jQuery] Having a problems with $.post() and external .js files

2009-08-21 Thread m...@polyvisual.co.uk

Hi all,

Can someone help? I'm having a problem with $.post() and including
external .js files.

I include my jquery in the header of each page:



I have a php file which includes a form [an external php file called
searchformbox.php]. Each time a  is changed in the
form, jquery handles the submit by doing a $.post() and sending all
the form variables back to searchformbox.php. The searchformbox.php
with the new form options is reloaded its  by using .html()

What I have found, is that if I don't re-include the external .js file
in searchformbox.php, the jquery does not trigger the second time a
 is changed.

The answer [it seems] is to re-include the external .js file in
searchformbox.php. However, this causes the jquery to be triggered
twice (obviously causing twice the number of mysql queries and a GET
to reload the common.js file).

I [think I] understand why the jquery is triggered twice, but I can't
understand how to stop it. It seems like a catch 22 problem... can
anyone help?

Thanks :)

Here's the jquery I use for the form resubmit [each  has the
class .selector]:

$(".selector").change(function(){

   $("#loadingbox").show();


   var brand = $('#brand').val()
   var oldbrand = $('#oldbrand').val()
   var model = $('#model').val()
   var freegift = $('#freegift').val()
   var minutes = $('#minutes').val()
   var texts = $('#texts').val()
   var contractlength = $('#contractlength').val()
   var price = $('#price').val()
   var phoneprice = $('#phoneprice').val()

   var selectednetworks = [];
$('@name=network:checked').each(function() {
  selectednetworks.push($(this).val());
});

   $.post("searchformbox.php", {
'selectednetworks[]':selectednetworks, phoneprice: phoneprice, price:
price, brand: brand, model: model, freegift: freegift, minutes:
minutes,
texts: texts, contractlength: contractlength, oldbrand: oldbrand },

   function(data){
   $("#searchbox").html(data);
   }
);

});


[jQuery] Re: Having a problems with $.post() and external .js files

2009-08-21 Thread m...@polyvisual.co.uk

Thank you for replying.

Yeah, that make sense to me. I'll try it when I get home.

Thanks again :)



On Aug 21, 10:47 am, Dhruva Sagar  wrote:
> In my opinion the problem of it not triggering the second time when your
> .php file has loaded a new form is because it is a new .select tag!The not
> triggering has nothing to do with including of the .js file.
> What you need to ensure is after the $.post, when you update the form using
>
> $('#searchbox').html(data);
>
> you should at the same time actually be attaching the 'change' trigger to
> the '.selector'
>
> I hope you understand.
>
> Here is how it should be done in my opinion :
>
> function onSelectorChange() {
>
> $("#loadingbox").show();
>
>       var brand = $('#brand').val()
>       var oldbrand = $('#oldbrand').val()
>       var model = $('#model').val()
>       var freegift = $('#freegift').val()
>       var minutes = $('#minutes').val()
>       var texts = $('#texts').val()
>       var contractlength = $('#contractlength').val()
>       var price = $('#price').val()
>       var phoneprice = $('#phoneprice').val()
>
>       var selectednetworks = [];
>            $('@name=network:checked').each(function() {
>              selectednetworks.push($(this).val());
>            });
>
>       $.post("searchformbox.php", {
> 'selectednetworks[]':selectednetworks, phoneprice: phoneprice, price:
> price, brand: brand, model: model, freegift: freegift, minutes:
> minutes,
> texts: texts, contractlength: contractlength, oldbrand: oldbrand },
>    onPost
>
> }
>
> $('.selector').change(onSelectorChange);
>
> function onPost() {
>      $("#searchbox").html(data);
>      $('.selector').change(onSelectorChange);
>
> }
>
> I hope the syntax & the bracket '{', '}' are in correct order above.
> But more importantly I hope you get the idea...
>
> Thanks & Regards,
> Dhruva Sagar.
>
> Ted Turner <http://www.brainyquote.com/quotes/authors/t/ted_turner.html>  -
> "Sports is like a war without the killing."
>
> On Fri, Aug 21, 2009 at 2:52 PM, m...@polyvisual.co.uk <
>
> m...@polyvisual.co.uk> wrote:
>
> > Hi all,
>
> > Can someone help? I'm having a problem with $.post() and including
> > external .js files.
>
> > I include my jquery in the header of each page:
>
> > 
>
> > I have a php file which includes a form [an external php file called
> > searchformbox.php]. Each time a  is changed in the
> > form, jquery handles the submit by doing a $.post() and sending all
> > the form variables back to searchformbox.php. The searchformbox.php
> > with the new form options is reloaded its  by using .html()
>
> > What I have found, is that if I don't re-include the external .js file
> > in searchformbox.php, the jquery does not trigger the second time a
> >  is changed.
>
> > The answer [it seems] is to re-include the external .js file in
> > searchformbox.php. However, this causes the jquery to be triggered
> > twice (obviously causing twice the number of mysql queries and a GET
> > to reload the common.js file).
>
> > I [think I] understand why the jquery is triggered twice, but I can't
> > understand how to stop it. It seems like a catch 22 problem... can
> > anyone help?
>
> > Thanks :)
>
> > Here's the jquery I use for the form resubmit [each  has the
> > class .selector]:
>
> > $(".selector").change(function(){
>
> >       $("#loadingbox").show();
>
> >       var brand = $('#brand').val()
> >       var oldbrand = $('#oldbrand').val()
> >       var model = $('#model').val()
> >       var freegift = $('#freegift').val()
> >       var minutes = $('#minutes').val()
> >       var texts = $('#texts').val()
> >       var contractlength = $('#contractlength').val()
> >       var price = $('#price').val()
> >       var phoneprice = $('#phoneprice').val()
>
> >       var selectednetworks = [];
> >            $('@name=network:checked').each(function() {
> >              selectednetworks.push($(this).val());
> >            });
>
> >       $.post("searchformbox.php", {
> > 'selectednetworks[]':selectednetworks, phoneprice: phoneprice, price:
> > price, brand: brand, model: model, freegift: freegift, minutes:
> > minutes,
> > texts: texts, contractlength: contractlength, oldbrand: oldbrand },
>
> >       function(data){
> >               $("#searchbox").html(data);
> >       }
> > );
>
> > });


[jQuery] passing the state of a checkbox on a page reload

2009-05-01 Thread m...@polyvisual.co.uk

Hi

I have a div which contains a search box and gets hidden when the page
loads. A user can click a link to reveal the div.

If I added a checkbox inside the div with the text 'click this box to
always keep this search box open'... how would I pass the state of the
checkbox to jquery [to not change the css to hidden] after the user
has done a new search and reloaded the page?

Thanks

Matt


[jQuery] malsup.com form and php validation confusion

2009-02-09 Thread m...@polyvisual.co.uk

Hi all,

I'm using the jquery form plugin from malsup.com, and I'm confused
about validation.

I need to validate the form fields in the php file specified in the
action of the form.

I realise I can use the success: function() to update a div (I
actually want to perform animation on a div elsewhere on the page)
when successful, but if the form is incorrectly completed, how do I
return a 'failed' code from the php file (so that the animation
doesn't happen)?

(It seems to me as though the form always returns 'successful' code ?)

Thanks,

Matt


[jQuery] Re: malsup.com form and php validation confusion

2009-02-09 Thread m...@polyvisual.co.uk

Thanks for replying, Mike.

I see.

In the success: function() I'll use match() on the responseText to
check whether the form validated, and then do whatever I require.
Thanks,

Matt



On Feb 9, 11:15 pm, Mike Alsup  wrote:
> > (It seems to me as though the form always returns 'successful' code ?)
>
> If the HTTP request is successful then the success function is
> invoked. This is no different than using jQuery's $.ajax function.  A
> request is deemed to be successful it the server response has a
> statusCode of 2xx or 304.  You could choose to set an error status
> code to drive the desired client behavior or you could return a 200
> status with content in the response body.  That content would then be
> passed to your success callback and you could interrogate it as needed.