1

In the code below, I want to change the line of code that reads as:

$("#commentload"+ID).prepend(html);

So that if the parameter order=1 is found in the URL, for example, http://my.com?order=1then it should execute.

$("#commentload"+ID).append(html);

Instead of

$("#commentload"+ID).prepend(html);

Hope you understand what I mean.

$(document).ready(function(){
   // Update Status
   $(".update_button").click(function(){
      var updateval = $("#update").val();
      var dataString = 'update='+ updateval;
      if(updateval==''){
         alert("Please Enter Some Text");
      } else {
         $("#flash").show();
         $("#flash").fadeIn(400).html('Loading Update...');
         $.ajax({
            type: "POST",
            url: "message_ajax.php?CID=" + CID + "&Id="+Id,
            data: dataString,
            cache: false,
            success: function(html){
               $("#flash").fadeOut('slow');
               $("#commentload"+ID).prepend(html);
               $("#update").val('');
               $("#update").focus();
               $("#stexpand").oembed(updateval);
            }
         });
      }
      return false;
   });
   //commment Submit
});
JCOC611
  • 19,111
  • 14
  • 69
  • 90
  • I've formatted your post for you. Please remember to indent code four spaces to format it. The styling will usually recognize which language it is. If it doesn't, you can prefix it with ``, with `etc` being short-hand such as `js` for `javascript`, `css` for `cascading style sheets`, or similar. – Daedalus Nov 04 '12 at 04:04
  • Thanks Daedalus! I'm still new to the styling. You spoonfed me then, but I will learn from this. Many thanks. – Frankie 'Moodurian' Kam Nov 04 '12 at 04:15

1 Answers1

4

You can get the current URL using location.href (or location.search, since you're only interested in the query portion). Search it for your parameter, for instance using a regex:

if ( /order=1/.test(location.href) )
    $("#commentload"+ID).append(html);
else
    $("#commentload"+ID).prepend(html);

If you need a more general solution, see this related question (or this one, as suggested by @naveen).

Community
  • 1
  • 1
mgibsonbr
  • 21,755
  • 7
  • 70
  • 112