Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Another 'Why doesn't this work' simple question.
Old 06-18-2010, 07:07 PM Another 'Why doesn't this work' simple question.
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Well, I'm a noob at javascript, but I'm trying to make a script that will replace text in a textarea. Just certain text, though. Here's what I've got:

Code:
<script type="text/javascript">
function add(Ident) {
  if (document.getElementById(Ident).style.background!="green") {
    document.getElementById(Ident).style.background='green';
    var curText = document.getElementById('locationtext').value;
    document.getElementById('locationtext').value = curText + Ident + " ";
  }
  else {
    document.getElementById(Ident).style.background='white';
    locTextArea = document.getElementByID('locationtext').innerHTML;
    locTextArea.innerHTML = locTextArea.replace(Ident, "DELETED");
  }
}
</script>
<textarea id="locationtext"></textarea>
Shortened, I can give the whole page's code (the content), but that's the point. Right now I just want it to delete the ID found by the variable 'Ident' in the function add with 'DELETED'. But this doesn't work .

Please help me, noob question :P

Thanks,

-PG
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-18-2010, 07:21 PM Re: Another 'Why doesn't this work' simple question.
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Woah, sorry chrishirst, I edited it but it added a new message? :?

But does anybody have an answer to my question Thanks
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 06-18-2010, 07:24 PM Re: Another 'Why doesn't this work' simple question.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Have a look at

http://www.webmaster-talk.com/javasc...tml#post772383
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-18-2010, 07:27 PM Re: Another 'Why doesn't this work' simple question.
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Thanks, but that doesn't seem to do exactly what I need

Plus, is there an easier (and shorter) way to do it? I want to be able to understand the code too . I know I can learn, and I do want to, but that's a lot D:
Like, what's wrong with mine? My problem starts after the 'else {'. It turns it back to white, but it doesn't delete the text ????
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 06-18-2010, 07:37 PM Re: Another 'Why doesn't this work' simple question.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Because textarea elements have a value property not a innerHTML property
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-18-2010, 07:43 PM Re: Another 'Why doesn't this work' simple question.
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Ah, ok...

I fixed it, but it still doesn't work ??

Code:
function add(Ident) {
  if (document.getElementById(Ident).style.background!="green") {
    document.getElementById(Ident).style.background='green';
    var curText = document.getElementById('locationtext').value;
    document.getElementById('locationtext').value = curText + Ident + " ";
  }
  else {
    document.getElementById(Ident).style.background='white';
    locTextArea = document.getElementByID('locationtext').value;
    locTextArea.value = locTextArea.replace(Ident, "DELETED");
  }
}
Grr. Stupid Javascript
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 06-20-2010, 06:39 AM Re: Another 'Why doesn't this work' simple question.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
locTextArea = document.getElementByID('locationtext').value;
locTextArea.value = locTextArea.replace(Ident, "DELETED");
You define 'locTextArea' as = locTextArea.value then try to set a property of .value as well

locTextArea.value.value does NOT exist.

You have got a bit confused between assigning variables to objects and assigning variables to a property of the object.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-20-2010, 07:54 PM Re: Another 'Why doesn't this work' simple question.
Physicsguy's Avatar
404 - Title not found

Posts: 919
Name: Scott Kaye
Location: Ontario
Trades: 0
Ah, thanks! I ended up just deleting the whole function and re-writing it, it can be found here. Tell me if you liek
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Another 'Why doesn't this work' simple question.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29019 seconds with 12 queries