aneeb Posted August 11, 2012 Share Posted August 11, 2012 Hey everyone! i want to get some specific parameters from URL. If the url contains id then do this and if the url contains userno then do this and if it didn't contain anything do this. I want to put it in If else statement. the url is like this If it didn't contain anythinghttp://localhost:8080/web/promotions.html If it contains idhttp://localhost:8080/web/promotions.html?id=Food If it contain usernohttp://localhost:8080/web/promotions.html?userno=12 How can i do this? Please help me i am new to this.. Link to comment Share on other sites More sharing options...
niche Posted August 11, 2012 Share Posted August 11, 2012 ajax call and the $_GET array. See:http://www.w3schools.com/php/php_ajax_intro.asp Link to comment Share on other sites More sharing options...
aneeb Posted August 11, 2012 Author Share Posted August 11, 2012 I am doing it like this if((location.search=="") ? "" : "userno"){ var get = ''; var userno = getUrlVars()["userno"]; get = 'getpromotions.php?userno='+userno;}else if((location.search=="") ? "" : "id"){ var get = ''; var id = getUrlVars()["id"]; get = 'getpromotions.php?id='+id;}else{ var get = ''; get = 'getpromotions.php'; } In this only If and Else are working, else if statement is not working.. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2012 Share Posted August 13, 2012 It's "working", but it's never going to go into that block because the second if statement checks the same condition as the first if statement. Both of them will only execute if location.search is empty, and if it's empty then only the first block will get executed. Link to comment Share on other sites More sharing options...
aneeb Posted August 13, 2012 Author Share Posted August 13, 2012 So how can i do it ? please tell me.. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2012 Share Posted August 13, 2012 What exactly are you trying to do with that code? It sounds like you should save the return value of getUrlVars and then check if items in the array are undefined. Link to comment Share on other sites More sharing options...
aneeb Posted August 13, 2012 Author Share Posted August 13, 2012 I want to check the URL, if the URL contains id then do this, if it contains userno then do this and it didn't contain anything then do this... Can you tell me a different code for doing this?? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2012 Share Posted August 13, 2012 Save the results and check each one. var urlVars = getUrlVars();var urlId = '';var urlUserno = '';if (urlVars['id'] != undefined) urlId = urlVars['id'];if (urlVars['userno'] != undefined) urlUserno = urlVars['userno']; Now you can check the values of urlId and urlUserno to figure out what you want to do. 1 Link to comment Share on other sites More sharing options...
aneeb Posted August 13, 2012 Author Share Posted August 13, 2012 Thank you sir, it works thanks alot...May God bless you.. Link to comment Share on other sites More sharing options...
Don E Posted August 13, 2012 Share Posted August 13, 2012 Just a quick question... is getUrlVars() a user-defined function or of some library? Thanks. Link to comment Share on other sites More sharing options...
aneeb Posted August 13, 2012 Author Share Posted August 13, 2012 getUrlVars() is a pre-defined function. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now