convert Jquery to ASP

Hi,

I have these two JQuery functions that I would like to run serverside in classic ASP.

Can somebody help me to convert these please?

function getQsValue(name) {
    get_string = document.location.search;
    return_value = '';
    do {
        name_index = get_string.indexOf(name + '=');
        if (name_index != -1) {
            get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
            end_of_value = get_string.indexOf('&');
            if (end_of_value != -1) value = get_string.substr(0, end_of_value);
            else value = get_string;
            if (return_value == '' || value == '') return_value += value;
            else return_value += ', ' + value
        }
    } while (name_index != -1) space = return_value.indexOf('+');
    while (space != -1) {
        return_value = return_value.substr(0, space) + ' ' + return_value.substr(space + 1, return_value.length);
        space = return_value.indexOf('+')
    }
    return (return_value)
}

function getCookieValue(cookiename) {
    var nameEQ = cookiename + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)
    }
    return null
}

Open in new window


What is the ASP equivalent of onload too?

Thanks
Al4ddin2Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
nap0leonConnect With a Mentor Commented:
You javascript function "getQsValue(name)" merely returns the value from the URL parameter.  The ClassicASP function you want to use is 'Request.QueryString("name")'

example:
if you are looking for First Name from a URL parameter, your javascript could look like this:
var Firstname = getQsValue('Firstname')'

Open in new window

the ASP version of this is:
Firstname = Request.QueryString("Firstname")

Open in new window


Padas already gave an example of the cookies, but to summarize here it is:
If you are looking for the value of the First Name cookie, your javascript could look like this:
var Firstname = getCookieValue('Firstname');

Open in new window

the ASP version of this is
Firstname = Request.Cookies("Firstname")

Open in new window

0
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
What is it you want to do rather then just re do a client side function?  In theory, you could actually load jquery and process some jquery functions serverside with asp.  However, it would be very slow.  Also jquery is typically meant to rearrange things after all html has been loaded so most of it would not work.  Your asp/vb or asp/js runs before the page loads (server side) and javascript / jquery runs after all html, css etc has been loaded. (client side).

It looks like the equivalents for the two functions are instr() and cookies().

Instr http://www.w3schools.com/vbscript/func_instr.asp

txt="This is a beautiful day!"
response.write(InStr(1,txt,"i") ' should show 3 since the letter i is in the 3rd position and we are starting from the 1st character.

response.write(InStr(7,txt,"i") ' should show 16 since we are starting from the 7th character and the first letter i is the 16th spot when we start from the 7th.

Doing this serverside with asp will work great if you are searching a word or sentence or short paragraph.  However, if you are searching the entire page, it is best left to javascript.

cookies   http://www.w3schools.com/asp/asp_cookies.asp

To write a cookie,  Response.Cookies("firstname")="Alex" and to read it
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)

If you drop a cookie with your asp/vb or asp/js you will be able to read it with your client side javascript since the js loads after everything else.  However, you would not be able to read a cookie dropped by client side with server side asp UNLESS the page is refreshed or another page is loaded.

Without seeing more details, this is the best I can help.  If you have a specific portion of code you are trying to recreate, start a new question for each using specific code examples of what you have and what you are trying to do.  Then we can help in more detail.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.