473,700 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementById: Undefined??

178 New Member

I have written a function that creates a new object, the problem I am having is trying to refer to these objects in another function. When using getElemenntById I get a value "undefined" . Does anyone know where im going wrong?

Expand|Select|Wrap|Line Numbers
  1. function showObject (){
  2.     if (request.readyState == 4) {
  3.     var returned = request.responseText;
  4.     var splitResult = returned.split(" ");
  5.     var h = splitResult[0];
  6.     var w = splitResult[1];    // the dimensions must be set to a scale as they are to big for the screen. 25px represents 100mm
  7.     h = h/5;
  8.     w = w/5;
  10.     cv = document.getElementById("canvas");
  11.     var newObject = document.createElement('div');
  12.     newObject.Class = g_objName;
  13.     newObject.id = "newObject";
  14.     newObject.innerHTML = g_objName;
  15.     newObject.alt = g_objName;
  16.     newObject.style.height = h;
  17.     newObject.style.width = w;
  18.     newObject.onmousedown=function(){grab(this);}    
  19.     cv.appendChild(newObject);
  20. }
  21. }
  23. function render () {
  24.     var ww = document.getElementById("newObject").value;
  25.     alert(ww);
  28. }
Jul 28 '08 #1
2 3544
54 New Member
I'm not sure about this, but you might want to try to add this (don't replace the old method of setting the id, just add this one right after it):
Expand|Select|Wrap|Line Numbers
  1. newObject.setAttribute('id', 'newObject');
Also, you want to add a line in the showObject() function which sets a variable to true and then write it using an alert at the begining of render() so you're sure that showObejct() is called before render().

Jul 28 '08 #2
178 New Member
i worked it out. I needed the .id instead of .value

Thanks anyway.
Jul 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: John Ramsden | last post by:
.... when the id 'junk' doesn't exist anywhere in the document, instead of returning 'object'?! I am using Javascript for a drop-down menu, slightly adapted from one by Angus Turnbull (see http://javascript.internet.com and http://gusnz.cjb.net, not that this is probably relevant but it deserves a plug ;-), on Internet Explorer v6.0.2800.1106. I need this feature of getElementById(), or an equivalent one (using sound and standard...
by: dlolsen | last post by:
I still not advanced at javascript and I am trying to do a picture portfolio page where there is a scrollable area with thumbnails. When you click on the thumbnail, I want to use document.getElementIDBy to change which picture is displayed in the fullsize area. Everything seems right, but I keep getting an error: *Line: 3 | Error: Expected ';' * I am kinda boggled because I clearly closed with * ; * If anyone could help, or if there...
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with both single quotes and no single quotes, but it doesn't work either way. What am I doing wrong? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById('weblogs').style.visibility='hidden';
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and have the function update the target ID with the URL. There is a bit more to it then that, but that is the basics. my difficulty comes when I try to assign a variable to: "document.getElementById('-> var gose here <-').innerHTML"
by: bcr07548 | last post by:
I am writing a web site that uses JavaScript to validate certain forms and I seem to be having some trouble. The site uses PHP and for one of the forms, depending on the situation, one of of the text inputs does not exist - the PHP doesn't generate the HTML for it. I wanted to have the validation script check the length of the input if it exists but I knew that I might have trouble if I tried to check the value of the input without first...
by: noddy | last post by:
I need to retrieve some notes from a database, allow users to modify them and then return them to the database.I have done this satisfactorily using php.However I would like to do it using AJAX. To this end I have a <divthe innerhtml for which is sent from a php file. The innerhtml constructs and fills a series of textareas and provides each with an id. When I want to return the modified note to the database and try to copy the text...
by: ratcateme | last post by:
I have this script to validate my reregistration form then send it to a AJAX handler to create the new user my problem is that when getting the value of the username and password filed it returns blank not "undefined" but just "" but it returns the rest of my form fine. my JavaScript is: function send(){ var user = document.getElementById('user').value; alert(document.getElementById('user').value); var pass =...
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my site and so far doing this has saved about 8KB of javascript (lots of ajax/dynamic elements). I just
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the script to update the display to the user depending on what they choose (qty, options, shipping etc.) I'm sure it's simple but I could really use a hand. Thanks!!
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
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...
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...
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...
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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...
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
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.