We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Calling javascript function using get?

I have written a form in html and wish to submit it and run some php code, however once the php file has finished it main job I want to use it to redirect to my homepage where I am using AJAX to change content (where the form is). Is it possible to redirect to a page with GET eg http://domain.com/homepage.php?variable=somevalue and then use that to call a javascript function?

Thanks for any help. I'm not sure that's the best explanation of my problem, please ask if you need clarification :)

2
Contributors
2
Replies
18 Hours
Discussion Span
10 Months Ago
Last Updated
3
Views
Question
Answered
dinners
Newbie Poster
17 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I'm still kind of confused with what you want to happen. But here I go, if you wanted to redirect a page using a javascript function, you may call window.location.href = 'url';

Then once you've redirected that user to the page and wanted to run some javascript function base on some get parameters, you can access the url's paramters using some function, see sample code below:

function getValue(url, name) {
    var result = {};
    var paramParts;
    var params = (url.split('?')[1] || '').split('&');

    for(var param in params) {
    if (params.hasOwnProperty(param)) {
    paramParts = params[param].split('=');
    result[paramParts[0]] = decodeURIComponent(paramParts[1] || "");
    }
    }
    if (result[name] === undefined && result[name] === null) {
    result = '';
    }
    return result[name];
}

you may call that function like getValue(window.location.href, 'variable_name')

it will return the value of the parameter you wanted to check on

lambing
Junior Poster in Training
76 posts since Feb 2010
Reputation Points: 10
Solved Threads: 15
Skill Endorsements: 0

Cheers that's brilliant. Exactly what I was trying to do!

dinners
Newbie Poster
17 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 10 Months Ago by lambing

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0623 seconds using 2.71MB