making a dynamic textarea name

All web design questions, hints and solutions can be discussed here.

Moderators: fac51, 117, Chris

Post Reply
vinnieza
Allowed to Drink!!!!
Posts: 3258
Joined: Sun Mar 07, 2004 12:09 pm
Location: Pluto
Contact:

making a dynamic textarea name

Post by vinnieza »

Hi, sorry i'm a major newbie at javascript. Anyway, my question:

I have a form called frmProfile, a textarea called article and a button with an onclick event set to addtext(this.form)

I have this function:

Code: Select all

addtext(form){
}


With this piece of javascript in it:

Code: Select all

var Article = form.article.value;


to get what is in the text area into a variable

The problem is this, i want to use this code for multiple forms on different pages, however all my text areas have different names. Now i was wondering is there anyway to add a variable to the js code so that it's easy to change all the times i refer to form.article.value?

I tried using var textareaName = "article"; and then i could change it on each of my pages and change the js code to something like:

Code: Select all

var Article = form.textareaName.value;


But you can't do that, well it doesn't work, guessing it's because the code does not realize it's suppose to be a variable and thinks that's the name of the textarea. Is there a sort of operator that tells it that it's a variable and not the name.

Thanks :)

sorry about the title wasn't sure of how to describe my problem
Image
....................My site: www.vthemes.co.uk
.........................* no questions asked *

Image
Chris
Web Design Guru
Posts: 1641
Joined: Fri Jun 27, 2003 8:16 pm
Location: England
Contact:

Post by Chris »

var txtareaname = "blabla"

mytextarea = document.getElementById(textareaname);


and just set id="blabla" to the textarea...
vinnieza
Allowed to Drink!!!!
Posts: 3258
Joined: Sun Mar 07, 2004 12:09 pm
Location: Pluto
Contact:

Post by vinnieza »

Where were you when i needed that lol :P

Thanks

Just used


Code: Select all

<textarea id="txtBB"...
document.getelementsbyid('txtBB').value


in the end :)
Image
....................My site: www.vthemes.co.uk
.........................* no questions asked *

Image
Post Reply