473,544 Members | 2,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get a handle to an object and verify if it exists?

SM
Hello,
I've created this 'wonderful' function the embeds a youtube video in a
specified div section using the Javascript DOM. Everything works OK...
until I realize how bad the logical programming was.
See, if you look at the function below, everytime i passed the youtube
video id, i create the object over and over and over .... again and
again and again..... you get the picture.
I could erase the object using [div.innertHTML = '' ] and created
again, but that's even worst! 10 times worst!!!!!!!!!!

These is probably a better logic:
Using an if statement, I want to check if the object exists. If not
created. If exist, then just replace the attribute 'value'.

Now for my question:
How do i get a handle to the object so i can verify if the object
exists or not?

Thanks
Marco
function video(id)
{
var w = 350;
var h = 288;

div = document.getEle mentById('mydiv '); //insert the newly created
object here

var obj = document.create Element('object ');
obj.setAttribut e('width', w);
obj.setAttribut e('height', h);

var param = document.create Element('param' );
param.setAttrib ute('name', 'movie');
param.setAttrib ute('value', 'http://www.youtube.com/v/' +id);
obj.appendChild (param);

var param = document.create Element('param' );
param.setAttrib ute('name', 'wmode');
param.setAttrib ute('value', 'transparent');
obj.appendChild (param);

var embed = document.create Element('embed' );
embed.setAttrib ute('width', w);
embed.setAttrib ute('height', h);
embed.setAttrib ute('wmode', 'transparent');
embed.setAttrib ute('type', 'application/x-shockwave-flash');
embed.setAttrib ute('src', 'http://www.youtube.com/v/' +id);
obj.appendChild (embed);

div.appendChild (obj);
}

May 2 '07 #1
2 5658
SM said the following on 5/2/2007 2:46 AM:
Hello,
I've created this 'wonderful' function the embeds a youtube video in a
specified div section using the Javascript DOM. Everything works OK...
until I realize how bad the logical programming was.
See, if you look at the function below, everytime i passed the youtube
video id, i create the object over and over and over .... again and
again and again..... you get the picture.
I could erase the object using [div.innertHTML = '' ] and created
again, but that's even worst! 10 times worst!!!!!!!!!!
Who told you that?
These is probably a better logic:
Using an if statement, I want to check if the object exists. If not
created. If exist, then just replace the attribute 'value'.

Now for my question:
How do i get a handle to the object so i can verify if the object
exists or not?

Thanks
Marco
function video(id)
{
var w = 350;
var h = 288;

div = document.getEle mentById('mydiv '); //insert the newly created
object here
if (document.getEl ementById('some ID'){
var obj = document.create Element('object ');
obj.id = 'someID'

<snip lots of setAttribute code that should use direct access instead>
div.appendChild (obj);
}
}
Give it an ID attribute and check for it when you enter the function.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 2 '07 #2
SM
On May 2, 9:03 am, Randy Webb <HikksNotAtH... @aol.comwrote:
SM said the following on 5/2/2007 2:46 AM:
Hello,
I've created this 'wonderful' function the embeds a youtube video in a
specified div section using the Javascript DOM. Everything works OK...
until I realize how bad the logical programming was.
See, if you look at the function below, everytime i passed the youtube
video id, i create the object over and over and over .... again and
again and again..... you get the picture.
I could erase the object using [div.innertHTML = '' ] and created
again, but that's even worst! 10 times worst!!!!!!!!!!

Who told you that?
These is probably a better logic:
Using an if statement, I want to check if the object exists. If not
created. If exist, then just replace the attribute 'value'.
Now for my question:
How do i get a handle to the object so i can verify if the object
exists or not?
Thanks
Marco
function video(id)
{
var w = 350;
var h = 288;
div = document.getEle mentById('mydiv '); //insert the newly created
object here

if (document.getEl ementById('some ID'){
var obj = document.create Element('object ');

obj.id = 'someID'

<snip lots of setAttribute code that should use direct access instead>
div.appendChild (obj);
}
}

Give it an ID attribute and check for it when you enter the function.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptT oolbox.com/bestpractices/
Hey Randy,
It works fine, except i can't get a handle on the 2 other child object
(param and embed). I need to access their respective values.
How do i get handle to those child objects
I tried using: objElem.param.g etAttribute('va lue'); with no success!

Thanks
Marco

---------------------------
var w = 350;
var h = 288;

divContent = document.getEle mentById("conte nt");

if(document.get ElementById('ob jectID'))
{
alert('object FOUND!');
var objElem = document.getEle mentById('objec tID')

***** DOESNT WORK*****
var value = obj.param.getAt tribute('value' );
}

else
{
alert('object NOT FOUND... create please');

var obj = document.create Element('object ');
obj.id = 'objectID';

obj.setAttribut e('width', w);
obj.setAttribut e('height', h);

var param = newElement('par am', 'movie');
param.setAttrib ute('value', 'http://www.youtube.com/v/' +id);
obj.appendChild (param);

var param = newElement('par am', 'wmode');
param.setAttrib ute('value', 'transparent');
obj.appendChild (param);

var embed = document.create Element('embed' );
embed.setAttrib ute('width', w);
embed.setAttrib ute('height', h);
embed.setAttrib ute('wmode', 'transparent');
embed.setAttrib ute('type', 'application/x-shockwave-flash');
embed.setAttrib ute('src', 'http://www.youtube.com/v/' +id);
obj.appendChild (embed);

divContent.appe ndChild(obj);
}

May 2 '07 #3

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

Similar topics

0
1967
by: John J. Lee | last post by:
I had the bright idea a week or two ago to construct mock objects (for unit testing) "by example" by calling methods on a generic mock object. Say we have a class Bar, and we want to check that, when we use BarUser in a particular way, BarUser first calls method Bar.xyzzy with args "foo" and bar=2, then method Bar.do_nothing. # first,...
5
5660
by: Dan Williams | last post by:
Apologies for the cross-post but i thought i'd aim for the largest audience possible. I have a web site that users have to register to with their email address. The site then emails the user their password via Exchange 2000 and ASP/VBScript and CDO. Does anyone know if its possible to verify that the email address exists before sending...
14
10112
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought I should give back to the community by posting our findings. Thanks you all for all your help till now by posting problems and their solutions. ...
1
7845
by: iam247 | last post by:
Hi I am a relative beginner with SQL and ASP. With some help after previous posts I have a page which successfully requests querystrings from another page and deletes a record from an access table, However, I get the error message: "Row handle referred to a deleted row or a row marked for deletion" I am using access 2002, the table...
7
1803
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to call the Win32 version in order to set the security descriptor for the mutex, which is not natively supported in .NET Framework 1.1. I always get...
2
4494
by: MrMike | last post by:
This is a tough one, but here goes. I have a webform textbox where users input a filepath. For example: \\servername\sharename\file.xls. Is there anyway that I could use VB code to verify that the filepath and filename are valid after the user has input them? Basically this would serve to quality check whether or not the user has input...
2
5256
by: Wayne Wengert | last post by:
I want to write a Windows application to go through all the email addresses in an SQL Server table and to report which ones are invalid. From Googling and perusing NGs it is my understanding that the process to validate an email address is done at 3 levels: 1. Verify that it is syntactically valid 2. Verify that the domain exists (SMTP...
3
7923
by: akadelski | last post by:
I need a way to verify a file exists before I attempt to open it. Right now we are storing PDFs server-side and I need a way to either 1. Check if the physical file exists or 2. check if the URL exists. I'm opening the PDFs with the following: var Win=open(theLinkURL,"",linkString); I create theLinkURL dynamically and the file may or...
13
4894
by: Abhishek | last post by:
Hi, how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to happen in that window directly. Regards Abhishek
0
7437
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
7781
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
7389
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
5928
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...
0
4930
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
3427
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
3421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1848
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
0
677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.