473,889 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing objects into javascript functions

I have a fairly simple problem that I just cant seem to figure out. I
am trying to pass and use a div in a function. This is what I have so
far... it doesnt work though...

<script>
function divControl(divN ame){
divName.innerHT ML="test"
}
</script>

in the HTML I have three div's

<div id="test1"></div>
<div id="test2"></div>
<a onclick="divCon trol('test1')"> test3</a>

The system does not seem to recognize the divName in the function ?!?!

Any help would be greatly appreciated

Evan
Jul 23 '05 #1
7 29021
Evan wrote:
I have a fairly simple problem that I just cant seem to figure out. I
am trying to pass and use a div in a function. This is what I have so
far... it doesnt work though...

<script>
function divControl(divN ame){
divName.innerHT ML="test"
}
</script>

in the HTML I have three div's

<div id="test1"></div>
<div id="test2"></div>
<a onclick="divCon trol('test1')"> test3</a>

The system does not seem to recognize the divName in the function ?!?!

Any help would be greatly appreciated

Evan

http://jibbering.com/faq/#FAQ4_41

Addresses that issue directly.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #2
Lee
Evan said:

I have a fairly simple problem that I just cant seem to figure out. I
am trying to pass and use a div in a function. This is what I have so
far... it doesnt work though...

<script>
function divControl(divN ame){
divName.innerHT ML="test"
}
</script>

in the HTML I have three div's

<div id="test1"></div>
<div id="test2"></div>
<a onclick="divCon trol('test1')"> test3</a>

The system does not seem to recognize the divName in the function ?!?!

Any help would be greatly appreciated

You're not passing an object. You're passing a string
containing the id of an object. That string does not
have an innerHTML attribute.

You can either pass a reference to the object, or you can
try to obtain a reference to the object in the function:

<script type="text/javascript">
function divControl(divN ame){
var divRef=document .getElementById (divName);
divRef.innerHTM L="test"
}
</script>
In a production script, there should be error checking, too.

Jul 23 '05 #3
Lee wrote:
Evan said:
I have a fairly simple problem that I just cant seem to figure out. I
am trying to pass and use a div in a function. This is what I have so
far... it doesnt work though...


Another method is to pass the object reference, rather than just a
string. This can be simpler in some cases, the OP's script stays the
same but the HTML changes to:

...
<a onclick="divCon trol(document.g etElementById(' test1'))">test3 </a>

The difference here is that you are not bound to use getElementById, so
you can use any method (this, this.parentNode , this.form, etc.) to get
the reference and pass it to the function.

Cheers, Fred.
Jul 23 '05 #4
ev************* ****@hotmail.co m (Evan) wrote in message news:<53******* *************** ****@posting.go ogle.com>...
I have a fairly simple problem that I just cant seem to figure out. I
am trying to pass and use a div in a function. This is what I have so
far... it doesnt work though...

<script>
function divControl(divN ame){
divName.innerHT ML="test"
}
</script>

in the HTML I have three div's

<div id="test1"></div>
<div id="test2"></div>
<a onclick="divCon trol('test1')"> test3</a>

The system does not seem to recognize the divName in the function ?!?!

Any help would be greatly appreciated

Evan


Try this:
<script>
function divControl(divN ame){
divName.innerHT ML="test"
}
</script>
</HEAD>
<div id=test1></div>
<div id=test2></div>
<a href='' onclick="divCon trol(test1);ret urn false">test3</a>

Cheers
Raul
Jul 23 '05 #5
On 17 Oct 2004 00:48:50 -0700, Raul <dd*****@arraki s.es> wrote:

[snip]
Try this:
Please don't.
<script>
SCRIPT elements have a required type attribute.

<script type="text/javascript">
function divControl(divN ame){
divName.innerHT ML="test"
}
</script>
</HEAD>
<div id=test1></div>
<div id=test2></div>
<a href='' onclick="divCon trol(test1);ret urn false">test3</a>


You still aren't passing an object reference, just an undefined global
variable. That will do nothing but cause an error. I suggest you read the
FAQ (<URL:http://jibbering.com/faq/>), specifically section 4.41.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
There is no onClick for "<a>" anchor Tag's and the innerHTML will embed
HTML not Text.Check Out New Code it Should Work.

<SCRIPT LANGUAGE="JavaS cript">
<!--
//Javascript for Div Tag Creation.
function divControl(divN ame,divName1){
divName.innerTe xt="test";
divName1.innerT ext = "Deepak Kini";
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<!--Insert Text into Div Tags-->
<div id="test1"></div>
<a href="javascrip t:divControl(te st1,test2)">tes t3</a>
<div id="test2"></div>
<!-- End -->
Jul 23 '05 #7
On Sun, 17 Oct 2004 08:03:30 -0400, shailesh <sh*******@vasn et.co.in>
wrote:
There is no onClick for "<a>" anchor Tag's
Nonsense. Of course there is!
and the innerHTML will embed HTML not Text.
Wrong. If you assign only text, only text will be displayed (assuming
innerHTML is supported).
Check Out New Code it Should Work.
In IE, but few others. Better solutions have already been suggested.
<SCRIPT LANGUAGE="JavaS cript">
The language attribute is deprecated in favour of (required) type.

<script type="text/javascript">
<!--
Attempting to hide scripts is also an out-dated practice. All user agents
currently in use know what a SCRIPT element is, so they will not render
its contents even if they cannot execute the script.
//Javascript for Div Tag Creation.
function divControl(divN ame,divName1){
divName.innerTe xt="test";
divName1.innerT ext = "Deepak Kini";
The innerText property is a proprietary Microsoft mechanism that is not
supported very well by other browsers. Unless you're writing for IE only,
and the OP gave no indication of that, don't use it.
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<!--Insert Text into Div Tags-->
<div id="test1"></div>
<a href="javascrip t:divControl(te st1,test2)">tes t3</a>
You need to read the group FAQ (<URL:http://jibbering.com/faq/>).
<div id="test2"></div>
<!-- End -->


Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8

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

Similar topics

5
36429
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a variable with the "ref" syntax then it gets passed as a reference to the object and any changes to
5
1369
by: twizansky | last post by:
Hello, I have a problem with values of object properties changing seemingly on their own. I am completeley baffled and would appreciate any assistance. specifically, I have a class called eetosfermions with the follwing constructor: eetosfermions::eetosfermions(int id1, int id2, SUSYspectrum & ss):
3
3946
by: Nikki | last post by:
Hi, I would like to create a central storage place for javascript functions that I can then access from any of my asp.net projects. An example of what I need it for is as follows: I have a class library that contains a function I use all the time (to create a link around some text). That function in turn calls a javascript function. Usually I would have put the javascript on the
0
1806
by: hawklord451 | last post by:
To get a foot hold in the area of web services I have created the following small project. I have created a group of classes to describe a overall Request class. the Request Class is made from a Customer, Sub Contractor and Task Class. The Sub Contractor and Customer classes inherit from an abstract Organisation Class. I have created a Web Application that assigns user input to the Request Class (Through a DLL instance). I have then...
4
3474
by: sofeng | last post by:
The following link shows a chart I created about passing structures among functions. Would you review it and tell me if it requires any corrections? http://bp2.blogger.com/_lZhqNsiakm4/Reh26hy-JHI/AAAAAAAAAAk/wvyV3Yx8gSs/s1600-h/gif_1.gif Thank you. sofeng
1
2242
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call that variable in another Java script. Sample script <SCRIPT LANGUAGE="JavaScript"> function GetSelectedItem() { len = document.formname.selectname.length i = 0 chosen = "none"
14
6044
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared static inside functions (i.e. local static objects) 5. objects declared at file scope.
2
4338
polymorphic
by: polymorphic | last post by:
I am no longer good at Javascript and need help. I'm trying to embed pdf files in html then build some sort of navigation between the pdfs via the pdf numbered file name. I can generate the javascript functions to extract and manipulate strings, ints, etc but can't seem to deal with the variables I produce. For instance, if current embedded pdf filename is "1.pdf" and button "Next" is clicked then embed "2.pdf". I cannot seem to get the...
1
1673
by: billsahiker | last post by:
I have some javascript functions in an xslt file. Everything works and produces the desired html, except when using the visual studio debugger which gives the error "objects of type 'Script1' do not have such a member" and references the line and column where the "this" object is used, as in this.hourarray() Any ideas on what the problem is?
3
5809
by: JJ | last post by:
I am using a handler (processImage.ashx) to display an image. The image is displayed according to parameters passed in the querystring. The handerl is called via some clientside javascript. I want to send an array of unknown length to the handler. I am not sure whether the querystring is the best place to do this. What's the best way to send an array held in the client side javascript to the handler? Thanks in advance, JJ
0
9966
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
11199
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
10791
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
10894
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,...
1
7997
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...
0
5830
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4647
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
4251
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.