473,558 Members | 2,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string vs object

If I have:

<a href="javascrip t:myfunct('cool _links')" id="cool_links" >

and I refer to it as:
function myfunct(mylink)
{
document.getEle mentById[mylink]
}

then it is NOT reffered to as an object. I have to change my link to :
<a href="javascrip t:myfunct(cool_ links)" id="cool_links" >

Notice I took the tick marks out. I'm not telling u anything new here. The
question I have is how can I include the link id as:
<a href="javascrip t:myfunct('cool _links')" id="cool_links" > with the tick
marks and then refer to it as an object?

Mike
Jul 20 '05 #1
7 2222
Ivo

"Michael Hill" <hi****@charter .net> wrote in message
news:vn******** ****@corp.super news.com...
If I have:

<a href="javascrip t:myfunct('cool _links')" id="cool_links" >
Try this:
<a href="noscript. html" onclick="myfunc t(this);return false"
id="cool_links" >

See the word "this" (without quotes)? This is a reserved word in javascript,
referring to whatever element it finds itself in, in this case an <a> tag.
This will be interpreted as an object variable by the same function that you
wrote.
Notice also that using the javascript: protocol in href attribute is not a
good idea as it is not well supported by browsers. The href should be a
valid link to a document for script-impaired users. The onclick will handle
the javascript (no need for setting the protocol there), and if it return
false the href will be ignored.
Ivo

and I refer to it as:
function myfunct(mylink)
{
document.getEle mentById[mylink]
}

then it is NOT reffered to as an object. I have to change my link to :
<a href="javascrip t:myfunct(cool_ links)" id="cool_links" >

Notice I took the tick marks out. I'm not telling u anything new here. The
question I have is how can I include the link id as:
<a href="javascrip t:myfunct('cool _links')" id="cool_links" > with the tick
marks and then refer to it as an object?

Mike

Jul 20 '05 #2
yes the myfunct(this) is the same as if I used myfunct(cool_li nks).

Reason that I like somehow to store the string is that I created a hidden
variable like:
<input type='hidden' name='myhidden' value=''>

and would like to store the name of the object there so I can use it later
in javascript processing. If not I have to pass the object around through
each javascript function.

I dont think I can store the object there can I?

Mike
"Ivo" <no@thank.you > wrote in message
news:3f******** *************@n ews.wanadoo.nl. ..

"Michael Hill" <hi****@charter .net> wrote in message
news:vn******** ****@corp.super news.com...
If I have:

<a href="javascrip t:myfunct('cool _links')" id="cool_links" >
Try this:
<a href="noscript. html" onclick="myfunc t(this);return false"
id="cool_links" >

See the word "this" (without quotes)? This is a reserved word in

javascript, referring to whatever element it finds itself in, in this case an <a> tag.
This will be interpreted as an object variable by the same function that you wrote.
Notice also that using the javascript: protocol in href attribute is not a
good idea as it is not well supported by browsers. The href should be a
valid link to a document for script-impaired users. The onclick will handle the javascript (no need for setting the protocol there), and if it return
false the href will be ignored.
Ivo

and I refer to it as:
function myfunct(mylink)
{
document.getEle mentById[mylink]
}

then it is NOT reffered to as an object. I have to change my link to :
<a href="javascrip t:myfunct(cool_ links)" id="cool_links" >

Notice I took the tick marks out. I'm not telling u anything new here. The question I have is how can I include the link id as:
<a href="javascrip t:myfunct('cool _links')" id="cool_links" > with the tick marks and then refer to it as an object?

Mike


Jul 20 '05 #3
Ivo
"Michael Hill" <hi****@charter .net> wrote in message
news:vn******** ****@corp.super news.com...
"Ivo" <no@thank.you > wrote in message
news:3f******** *************@n ews.wanadoo.nl. ..

"Michael Hill" <hi****@charter .net> wrote in message
news:vn******** ****@corp.super news.com...
If I have:

<a href="javascrip t:myfunct('cool _links')" id="cool_links" >
and I refer to it as:
function myfunct(mylink)
{
document.getEle mentById[mylink]
}

The question I have is how can I include the link id as:
<a href="javascrip t:myfunct('cool _links')" id="cool_links" >
with the tickmarks and then refer to it as an object?

Mike


Try this:
<a href="noscript. html" onclick="myfunc t(this);return false"
id="cool_links" >

See the word "this" (without quotes)? This is a reserved word in

javascript,
referring to whatever element it finds itself in, in this case an <a> tag. This will be interpreted as an object variable by the same function that

you
wrote.
Notice also that using the javascript: protocol in href attribute is not a good idea as it is not well supported by browsers. The href should be a
valid link to a document for script-impaired users. The onclick will

handle
the javascript (no need for setting the protocol there), and if it return false the href will be ignored.
Ivo

yes the myfunct(this) is the same as if I used myfunct(cool_li nks).

Reason that I like somehow to store the string is that I created a hidden
variable like:
<input type='hidden' name='myhidden' value=''>

and would like to store the name of the object there so I can use it later
in javascript processing. If not I have to pass the object around through
each javascript function.

I dont think I can store the object there can I?

Mike


Please put your reply at the bottom. The Usenet convention is to have the
answer follow the question, like in real life.

The variable this.id can be passed around separately if you find the object
too clumsy. I tried the above <a> tag with this function myfunct(mylink) {
alert(mylink); // [object]
alert(typeof mylink); // object
alert(mylink.id ); // cool_links
alert(typeof mylink.id); // string
}

Btw, if the only purpose of the hidden input field is to store a string, why
not use a global variable? Global variables can even hold whole objects, so
you can check its offsetHeight or whatever you like whenever you like.
Ivo
Jul 20 '05 #4
"Michael Hill" <hi****@charter .net> wrote in message
news:vn******** ****@corp.super news.com...
If I have:

<a href="javascrip t:myfunct('cool _links')" id="cool_links" >
<quote cite="http://jibbering.com/faq/#FAQ4_24">
I have <a href="javascrip t:somefunction( )"> what ... ?
</quote>
and I refer to it as:
function myfunct(mylink)
{
document.getEle mentById[mylink]

<snip>

JavaScript uses square brackets in bracket notation property accessors,
for indexing arrays and to define array literals. Parentheses are used
for function calls. As you have it, this line of code is attempting to
read a property of the document.getEle mentById function. Because
JavaScript functions are objects this is feasible but the
document.getEle mentById function will not normally have a property with
a name that corresponds with the toString value of the myLink parameter
of the myfunct function.

Try:-
document.getEle mentById(mylink );
- instead. However, this function does not do anything with the result
of the function call so there is probably no point in calling the
function at all.

Note that getElementById retrieves references to DOM elements with the
corresponding ID attribute. Elements that only have NAME attributes must
be accessed by other means.

Richard.
Jul 20 '05 #5
[75 lines of quotation skipped]
Please put your reply at the bottom. The Usenet convention is to have the
answer follow the question, like in real life.


Like the famous chunk of FAQ that explains this :)

A: No.
Q: Should I post my reply above the quoted text?

Related to that (sorry if I'm impolite, but I have to say it): last time I checked the Usenet convention was
also to *edit your followups*. Please don't add 14 lines of content to 75 lines of redundant, badly-wrapped,
ugly-to-read quotations that are in no direct relation to what you're saying.

Didn't mean to insult you--and I don't claim I'm a guru of Usenet etiquette, either ... but let's keep trying.

Best regards
Hendrik Krauss

Jul 20 '05 #6
>
Try:-
document.getEle mentById(mylink );
- instead. However, this function does not do anything with the result
of the function call so there is probably no point in calling the
function at all.


This works. I had a string that I fed like:

mylink='my_link _id';
var tableLeft = getOffsetLeft( document.getEle mentById(mylink ) );

function getOffsetLeft(e l)
{
var ol = el.offsetLeft;
while ( ( el = el.offsetParent ) != null )
{
ol += el.offsetLeft;
}
return ol;
}

I got the proper value of the offset. Thanks for everyones help.
Jul 20 '05 #7
JRS: In article <3f************ ***********@new s.freenet.de>, seen in
news:comp.lang. javascript, Hendrik Krauss <us****@removet his.hendrik-
krauss.andthat. de> posted at Sat, 4 Oct 2003 14:37:03 :-

Related to that (sorry if I'm impolite, but I have to say it): last time I
checked the Usenet convention was
also to *edit your followups*. Please don't add 14 lines of content to 75 lines
of redundant, badly-wrapped,
ugly-to-read quotations that are in no direct relation to what you're saying.


A further convention that you yourself have ignored is to set the right
margin at (about) 72 characters, at least for text in paragraphs. This
is, in part, for display in traditional-sized windows; but it is also
helpful to the human eye - see any book or magazine.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
16331
by: Thomas | last post by:
It looks like the String.replace doesn't work in IE6.1. Anyone else has the same problem. I am using newest service package of IE and Win2K. Thanks
6
1380
by: Christopher Benson-Manica | last post by:
<html> <head> <script> var s=String( 'foo' ); alert( s ); s.bar='bar'; alert( s.bar ); </script></head></html> Why does the second alert produce 'undefined'? Are string objects
15
4299
by: Gabor Drasny | last post by:
Hi all, Could anyone tell me if the following code is guaranteed to work or not? #include <string> #include <iostream> int main() { const char* s = std::string("Hello World").c_str();
2
1023
by: cnickl | last post by:
I’m not sure where to post this, so I post it here. It’s more like a VC++.NET / Managed Code problem. Probably easy to fix for you guys. I want to use a String object as a parameter for a function. Here is what it should look like: String *a = "Hallo"; this->SomeClass->FormatString(a); this->label->Text = a;
2
2092
by: Mike Moore | last post by:
does anyone have an example of how to get the connection string object converted to a string variable type in order for me to call a function?
5
1909
by: rengeek33 | last post by:
I am building a SQL statement for Oracle and need one part of it to read: , myvar = null, myvar2 = "1", myvar3 = "0", myvar4 = null, etc. I am constructing this string using the String object with the following code: theSQL.Append(" , myvar = " & FormatValue(MyClass.DB_CHAR1, Me.MyVar))
10
9036
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use std::string::size or std::string::empty to deal with this condition? Thank you. string s = ""; if (s == ""); if (s.size == 0); if (s.empty());
3
2438
by: silverburgh.meryl | last post by:
Hi, If I have a std string object , how to convert a STD string object to an integer? Thank you.
1
1413
by: OccasionalFlyer | last post by:
I'm trying to overcome limitations in a function by passing a string object rather than a string primitive. The code to set the string object's attributes, however, seems to have no effect: var msg = new String( 'WARNING: Quiting now will cancel all changes up to this point, ' + 'leaving your schedule as it was when you began this session....
8
2709
by: David Lazos | last post by:
Hi All, I use Contains method of String object to determine if a string variable has another string, like that. *************************** ipAddress.Contains("127.0.0") **************************** supposing that, there is a string array like
0
7629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8061
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6183
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5455
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1164
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.