Solved

convert Jquery to ASP

Posted on 2013-01-02
2
261 Views
Last Modified: 2013-01-08
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
0
Comment
Question by:Al4ddin2
2 Comments
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 250 total points
ID: 38736660
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
 
LVL 18

Accepted Solution

by:
nap0leon earned 250 total points
ID: 38754651
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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question