We help IT Professionals succeed at work.

The Substring() Not Giving any value

savsoft
savsoft asked
on
<script language="javascript">
function gettablename(getdb)
{
var db=getdb;
db=db.substring(1,db.indexOf("/",1));
alert(db);
}
</script>
Comment
Watch Question

CERTIFIED EXPERT
Commented:
what is the db value?

it is probably throwing some exception there

try this way

try
{
db=db.substring(1,db.indexOf("/",1));
}
catch(e)
{
alert(e.message());
}

Author

Commented:
Its still not working.. Value is recieveing Well in function but substring function not working..

string is "/TestCMS/"
CERTIFIED EXPERT

Commented:
is there any error message coming in alert?

Author

Commented:
No...... It seems like stop execution on substring function.. tell me solution
CERTIFIED EXPERT

Commented:
var db="/TestCMS/";
db=db.substring(1,db.indexOf("/",1));
alert(db);

this solution gives me the correct table name.

What exactly is the db value name? Check if that value has some character that needs to be escaped

Author

Commented:
but if i pass value through function parameter then it is not giving any output.....

Author

Commented:
name is Excatly "TestCMS" which i send to function through escape string .. It stops working after any string function is called
how will you get indexOf("/") whe when you dont have / in your string :)

Commented:
savsoft:

Your function does not have a return statement.  The variable 'db' is a local variable that exists only within your function.  Try this:

<script language="javascript">
function gettablename(getdb)
{
var db=getdb;
db=db.substring(1,db.indexOf("/",1));
alert(db);

return db;
}
</script>

Regards,

AielloJ

Explore More ContentExplore courses, solutions, and other research materials related to this topic.