Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've a variable called url as follows :

url = "http://56.177.59.250/static/ajax.php?core[ajax]=true&core[call]=prj_name.contactform&width=400&core[security_token]=c7854c13380a26ff009a5cd9e6699840"

Now I want to use if condition only if core[call] is equal to the value it currently has i.e. prj_name.contactform otherwise not.

How should I do this since the parameter from query-string is in array format?

Please help me.

Thanks.

share|improve this question

closed as unclear what you're asking by Vohuman, T.J. Crowder, PeterKA, charlietfl, Alexander Dec 31 '14 at 14:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

3  
parse query string, look for value. I dont quite see the problem here. –  Fallenreaper Dec 31 '14 at 14:37
    
possible duplicate of How can I get query string values in JavaScript? –  Hacketo Dec 31 '14 at 14:38

2 Answers 2

up vote 3 down vote accepted

Just use String.indexOf and check if it is present (that is not -1, which means it doesn't exist)

if(url.indexOf("core[call]=prj_name.contactform") > -1){
   // valid. Brew some code here
}
share|improve this answer
    
i like this. It is simple. No need to convert and create a plethora of complicated objects, therefore it doesn't take up extra space, and only scans once, unlike parsers which will need to scan repetitively for keywords like '?' or '&'. This i feel is the best, and straightforward approach. –  Fallenreaper Dec 31 '14 at 14:43

You can use location.search :

 <script>
function get(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
if(get("core[call]") == "prj_name.contactform"){
    alert('ok');
}else{
    alert('no');
}
</script>
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.