473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

undefined getElementById

oll3i
679 512MB
Why
var offer=document.getElementById("editor_displaying_t ext").value;
returns undefined?
Thank You
Feb 13 '08 #1
13 2147
Why
var offer=document.getElementById("editor_displaying_t ext").value;
returns undefined?
Thank You
it's really hard to tell without knowledge of what "editor_displaying_text" is.

I'm going to go on a limb and say not all elements have a property called "value"... in fact, most do not. Unless "editor_displaying_text" is an "OBJECT", "PARAM", "LI", "INPUT" or "BUTTON", value will return undefined.

Read the DTD: http://www.w3.org/TR/html/DTD/xhtml1-transitional.dtd, do a CTRL-F for "value" and see how often it shows up.... not very often.

You may want to check out the "childNodes" array for a list of dom elements within the element -- or, if you like the cheap & easy way out, innerHTML.
Feb 14 '08 #2
oll3i
679 512MB
It's an editable div which id is editor_displaying_text
Thank You
Feb 14 '08 #3
acoder
16,027 Expert Mod 8TB
You'll have to show your code. Where do you define it within the page?
Feb 14 '08 #4
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1.  function makeBold(txt){
  2.  
  3.  var offer=document.getElementById("editor_displaying_text").value;
  4.  
  5.  
  6.  offer=offer+'\n' ;
  7.  
  8.  offer=offer.replace(txt,'<b>'+ txt +'</b>');
  9.  
  10.  document.getElementById("editor_displaying_text").value = offer;
  11.  }
  12.  
Feb 14 '08 #5
ronverdonk
4,258 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1.  function makeBold(txt){
  2.  
  3.  var offer=document.getElementById("editor_displaying_text").value;
  4.  
  5.  
  6.  offer=offer+'\n' ;
  7.  
  8.  offer=offer.replace(txt,'<b>'+ txt +'</b>');
  9.  
  10.  document.getElementById("editor_displaying_text").value = offer;
  11.  }
  12.  
That code still does not show the <div>

Ronald
Feb 14 '08 #6
acoder
16,027 Expert Mod 8TB
...and the code for the "editor"?

Edit: Ah, ronverdonk replied in the meantime!
Feb 14 '08 #7
ronverdonk
4,258 Expert 4TB
...and the code for the "editor"?

Edit: Ah, ronverdonk replied in the meantime!
Won't do it again.

Ronald
Feb 14 '08 #8
acoder
16,027 Expert Mod 8TB
Won't do it again.

Ronald
No, I didn't mean you did something wrong (in fact, quite the opposite)! I was in the middle of replying and by the time I replied, you'd already done so. I just added an edit in case it looked like a duplicate response.
Feb 14 '08 #9
ronverdonk
4,258 Expert 4TB
No, I didn't mean you did something wrong (in fact, quite the opposite)! I was in the middle of replying and by the time I replied, you'd already done so. I just added an edit in case it looked like a duplicate response.
I was just kidding. Nobody prevents me from meddling in other forums/fora/forae?

Ronald
Feb 14 '08 #10
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1.  <script language = "JavaScript">
  2.  
  3.  function getSelectedText(){
  4.  var txt = '';
  5. if (document.getSelection) txt = document.getSelection();
  6. else if (document.selection) txt = document.selection.createRange().text;
  7.  
  8. return txt;
  9.  
  10.  }
  11.  
  12.  
  13.  function makeBold(txt){
  14.  
  15.  var offer=document.getElementById("editor_displaying_text").value;
  16.  
  17.  document.write(offer);
  18.  offer=offer+'\n' ;
  19.  
  20.  offer=offer.replace(txt,'<b>'+ txt +'</b>');
  21.  
  22.  document.getElementById("editor_displaying_text").value = offer;
  23.  }
  24.  
  25.  
  26.  </script>
  27. </HEAD>
  28. <BODY>
  29. <form name="editor">
  30. <input type="button" name="bold"  class="editor_bold" onClick="makeBold(getSelectedText())">
  31. <input type="button" name="unordered_list" class="editor_unordered_list">
  32. <input type="button" name="anchor" class="editor_anchor">
  33.  
  34. </form>
  35.  
  36. <div id="editor_displaying_text" contenteditable="true" indicateeditable="true"></div>
  37.  
it is just my attempt to write a simple editor
Thank You
Feb 14 '08 #11
acoder
16,027 Expert Mod 8TB
I was just kidding. Nobody prevents me from meddling in other forums/fora/forae?

Ronald
Lol, you never know these days how people are easily offended.

Oll3i, as tswaters mentioned earlier, the div tag doesn't have a value attribute. Either use innerHTML or the DOM methods.

One other thing, you can't use document.write after the document has loaded.
Feb 14 '08 #12
oll3i
679 512MB
thank You that works I'm happy :)
Feb 14 '08 #13
acoder
16,027 Expert Mod 8TB
Glad to hear it!
Feb 14 '08 #14

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

Similar topics

6
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...
1
by: s_m_b | last post by:
here's the code (running from an ASP page): <script language = "JavaScript" type="text/javascript"> function initStuff() { var scanWindow = window.open('scanning.htm', 'scanning',...
2
by: Sam Samnah | last post by:
I posted this during the weekend and I think it was missed so I am posting it again. I'm in real big trouble with this and need help desperately. Any suggestions will be met with unbelievable...
7
by: dd | last post by:
Hello all. First, I'm a newbie to javascript but not to ASP. Secondly I've been searching for the answer for two hours and I decided to finally post this question. I'm trying to take a...
1
by: preet | last post by:
On first execution of StartSurf() the siteloc returns undefined On second excution and after that there is no problem. StartSurf is called from a button press, which becomes invisible for 30...
2
by: Moses | last post by:
Hi All, Is is possible to catch the error of an undefined element while creating an object for it. Consider we are not having an element with id indicator but we are trying to make the object...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
3
by: Alexio | last post by:
I need to apply an onLoad() event to call the function displayed below. I tried <body bgcolor="#B3FFB3" onLoad="display(obj)"> and it comes up with an error message of obj undefined. My question is...
1
by: selvialagar | last post by:
<?php require_once('database_conn.php'); session_start(); if(isset($_SESSION)) { if(isset($_GET) && $_GET=="submit") { $cust_id=$_POST; echo $cust_id; }
4
hemantbasva
by: hemantbasva | last post by:
We have designed an aspx page having five ajax tab in it. the data of first four are designed on page whereas for the fifth tab it renders a user control named MYDOMAIN. in the tab container's even...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.