Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    convert asp code to javascript

    greeting alls..seriously i'm hoping you guys can help me.
    i'm new with javascript thing

    can someone help me to convert this asp code (given below) to javascript?

    need help

    Function getID(instring)
    if instr(instring,"light") or instr(instring,"lite") then
    getID=7
    elseif instr(instring,"mix") then
    getID=8

    is it ok if i convert it to this :

    function getID(instring)
    {
    if (instring="light") || (instring="lite")
    {
    getID=7;
    }
    else if (instring="mix")
    {
    getID=8;
    }
    Last edited by fromhell; 08-13-2008 at 04:26 AM. Reason: futher explaination

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    What are you trying to do? How is getID being used in ASP? You should note that JS is client-side while ASP is server-side, anyway see if this helps:
    Code:
    function getID(instring)
    {
    var getID;
    if ((instring.toLowerCase()=="light") || (instring.toLowerCase()=="lite"))
    getID=7;
    else if (instring.toLowerCase()=="mix")
    getID=8;
    }
    Hope that helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i want this script to get an instring value and match it..and after that assign an id to getID...

    i try to write the code to this, but i just got an 'undefined' messagebox


    <script type = "text/javascript">

    function getID(instring)
    {

    if (instring.match("era"))
    {
    getID=8;
    }

    }

    alert(getID("era"))

    </script>
    Last edited by fromhell; 08-13-2008 at 05:59 AM. Reason: futher explaination

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    if (instring.match("era"))

    If you want to test whether value of the string is equal to era or ERA then:

    if (instring.toLowerCase() == "era") {
    getID = 8;
    alert (getID); // result is 8 if condition is true
    }

    If you want to test whether the string contains the sub-string era (e.g. abceraghj) then:-

    if (/(era)/gi.test(instring)) { // the i switch means ignore case

    You cannot use the same name (getID) for both a function and a variable. You need to rename the function.


    111,111,111 x 111,111,111 = 12,345,678,987,654,321
    Last edited by Philip M; 08-13-2008 at 08:07 AM.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    you know that you can simply run jscript on asp, it doesn't have to be vbscript.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •