473,789 Members | 2,925 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 2239
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
16346
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
1392
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
4342
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
1037
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
2101
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
1919
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
9070
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
2449
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
1422
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. ' + 'Are you sure you want to quit?' ); "msg".blink(); "msg".fontsize(7);
8
2715
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
9666
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
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.