converting a variable within a append document.forms string

B

barry

I have the following:
function(NAMED)
{
sString.Append("document.forms[0].NAMED.style.visibility = 'hidden'")
}

and would like to convert the NAMED into the object it represents - for
example in this case it represents the name of an image called card17

thanks
 
M

Mark Micallef

Hi Barry,

Where are you getting the Append() method from? Is this server or client
side code? Neither the .Net String class (v1.1) or the JavaScript string
class (v2.0) have an append method as far as I can tell.

If this is client-side javascript as I suspect, I would suggest the
following. The replace() method uses regular expressions (yuck!):

function namedSubstitude( ElementName )
{
// assumes sString is in scope for somewhere...
sString.replace(/NAMED/i, ElementName) ;
}

Hope this helps,
Mark
 
B

barry

Sorry, should have been more explicit
This is in a codebehind file and is using IsStartupScriptRegistered to run
the javascript
all of what follows is in the script code

I am passing to a function a name attribute from an img tag. I have checked
the name attribute and it is what I want but
when I try to use it in the following script code I can not get the passed
attribute to convert to its actual value.
I have tried using

The attribute passed is called card

sString.Append("document.forms[0]." + card + ".style.visibility =
'hidden'")

You would think the above would work but the attribute card needs to be put
in "card" for the syntax to work and of course this does not convert
properly

Any help is appreciated.

Mark Micallef said:
Hi Barry,

Where are you getting the Append() method from? Is this server or client
side code? Neither the .Net String class (v1.1) or the JavaScript string
class (v2.0) have an append method as far as I can tell.

If this is client-side javascript as I suspect, I would suggest the
following. The replace() method uses regular expressions (yuck!):

function namedSubstitude( ElementName )
{
// assumes sString is in scope for somewhere...
sString.replace(/NAMED/i, ElementName) ;
}

Hope this helps,
Mark
I have the following:
function(NAMED)
{
sString.Append("document.forms[0].NAMED.style.visibility = 'hidden'")
}

and would like to convert the NAMED into the object it represents - for
example in this case it represents the name of an image called card17

thanks
 
B

barry

Sorry, I was not more explicit
This is client side javascript in a codebehind
All of what I am about to say is in the javascript code
I have a img tag with a name attribute that I am passing to a function
The attribute when I run my browser over it shows up as the correct value
but will not convert in the code below

sString.Append("document.forms[0]." + card + ".style.visibility = 'hidden'")

First this gets a syntax error and I have to but the card(attribute passed)
in double quotes which will of course then not convert properly.

Any help would be appreciated.


Mark Micallef said:
Hi Barry,

Where are you getting the Append() method from? Is this server or client
side code? Neither the .Net String class (v1.1) or the JavaScript string
class (v2.0) have an append method as far as I can tell.

If this is client-side javascript as I suspect, I would suggest the
following. The replace() method uses regular expressions (yuck!):

function namedSubstitude( ElementName )
{
// assumes sString is in scope for somewhere...
sString.replace(/NAMED/i, ElementName) ;
}

Hope this helps,
Mark
I have the following:
function(NAMED)
{
sString.Append("document.forms[0].NAMED.style.visibility = 'hidden'")
}

and would like to convert the NAMED into the object it represents - for
example in this case it represents the name of an image called card17

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top