...

View Full Version : convert asp code to javascript



fromhell
08-13-2008, 05:23 AM
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;
}

rangana
08-13-2008, 06:06 AM
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:


function getID(instring)
{
var getID;
if ((instring.toLowerCase()=="light") || (instring.toLowerCase()=="lite"))
getID=7;
else if (instring.toLowerCase()=="mix")
getID=8;
}


Hope that helps.

fromhell
08-13-2008, 06:22 AM
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>

Philip M
08-13-2008, 09:02 AM
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

rnd me
08-13-2008, 06:57 PM
you know that you can simply run jscript on asp, it doesn't have to be vbscript.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum