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 :)

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.