0

Is there a jQuery event handler that will fire if a GET value is set? The equivalent of php's isset:

i.e.

if(isset($_GET["myValue"])){
}
user2755541
  • 536
  • 2
  • 10
  • 25
  • No, there is no event taking place. You can read said value though from the url. – Kevin B Mar 18 '14 at 21:17
  • My problem is that I'm using $.ajax method that is preventing the GET parameters from going into the url (because I have to use event.preventDefault() ). Is there a way around this? – user2755541 Mar 18 '14 at 21:22
  • @user2755541: It's not really clear what you're asking, and there's a good chance that the solution requires taking a step back and looking at the root of the problem, not where you're currently stuck in your assumed solution. Can you elaborate on what you're trying to accomplish? – David Mar 18 '14 at 21:24
  • @David - Yes, I have a function that processes a form using the get method when submitted. $('#myForm').submit(function(event) {//ajax stuff here} But I'd also like the get parameters to show up in the url, which is why I'm not using POST method, so that the results of the form processing can be replicated through the url. i.e. mysite.com?param1=myValue – user2755541 Mar 18 '14 at 22:14
  • Should I start a new question? – user2755541 Mar 18 '14 at 22:15
  • @user2755541 You should take some time to think about presenting what you **really** want to ask and what your problem is, **with** the current code you are trying. Once you have edited your question, then you might get an answer. – Neil Lunn Mar 19 '14 at 01:06

2 Answers2

0

You can check location.search contains your parameter:

if(location.search.indexOf("test=") != -1){
}
Wilmer
  • 2,511
  • 1
  • 14
  • 8
0

Use This function for any $_GET parameter.

function searchCheck(param){
  var a = Array();
  var b = Array();
    if(location.search.length>0){
      a= location.search.split('&');
      for(var index=0;index<a.length;index++){
         b= a[index].split('=');
        if(b[0]==param && b[1].toString()>0){
          alert(param+" already set");
          return true;
        }
      }
    }
alert(param+" not set");
return false;
}
4EACH
  • 2,132
  • 4
  • 20
  • 28