Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnClick add/remove text

Status
Not open for further replies.

theguru97321

IS-IT--Management
Joined
Feb 3, 2003
Messages
216
Location
US
I would like to have 'hidden' variables added to a TEXT AREA when a button is pressed, and removed if the button is pressed again.

The variables will be pulled from a MySQL database, and would be dynamic.

How would I go about doing this while keeping what ever text is already in the TEXTAREA.
 
You could try to store the contents of the TEXTAREA in a variable using:
Code:
var contents=document.formname.textareaname.innerHTML;

If you want to add/subtract text, use String functions to perform the necessary modifications, and then replace the contents using:
Code:
document.formname.textareaname.innerHTML=newContents;

Hope this helps.

Pete.


Web Developer & Aptrix / IBM Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
I'm not following very well. I'm not very good at Javascript yet.

I use PERL/CGI to output my code to html, Could you show the working code that would do this function?

 
Ok, I have a handle on it now. But I'm having some issues with the REPLACEMENT of text.

Check this out.

Code:
function inserttext(form,data) {
var te = new RegExp('<br>','gi');
if (data.match(te)){
data = data.replace(te, '\\r');
}
var ae = new RegExp(\"<ap>\",'gi');
if (data.match(ae)){
data = data.replace(ae, \"'\");
}
var be = new RegExp(\"<quote>\",'gi');
if (data.match(be)){
data = data.replace(be, '\"');
}
var ce = new RegExp(\"<contactlast>\",'gi');
if (data.match(ce)){
data = data.replace(ce, form.c_last_name.value);
}
var de = new RegExp(\"<contactfirst>\",'gi');
if (data.match(de)){
data = data.replace(de, form.c_first_name.value);
}
var ee = new RegExp(\"<contactpre>\",'gi');
if (data.match(ee)){
data = data.replace(ee, form.c_pre_name.value);
}
var fe = new RegExp(\"<userlast>\",'gi');
if (data.match(fe)){
data = data.replace(fe, form.u_last_name.value);
}
var ge = new RegExp(\"<userfirst>\",'gi');
if (data.match(ge)){
data = data.replace(ge, form.u_first_name.value);
}


if (form.content.value == '') {
//alert('empty');
form.content.value += data;
}
else if (form.content.value == data) {
//alert('only data');
form.content.value = '';
}
else {

var re = new RegExp(data); 
if (form.content.value.match(data)){
var newBodyHTML = form.content.value.replace(re, ''); 
//alert('removed data');
form.content.value = newBodyHTML;
}
else {
//alert('added data');

form.content.value = form.content.value + data;
}

}



return form.content.value;
}

But it never see that the 'content' contains the 'data' even tho when I add an alert(data); and alert(form.content.value); the LOOK IDENTICAL, but i can't tell what the code thinks is different.
 
replace this line:
form.content.value = form.content.value + data;

with this:
form.content.value += data;

and see if it works...

hope it helps

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
Since I already have that for the "empty" command, I didn't think it would change anything, and I was right.

Nice thought though, it did clean up my code a bit :)

Any other thoughts??

btw, this did work before I started doing the replacement commands. But I need those for the variables, and for formating the text properly.

If you can think of a better way to do that, I'm all ears.(eyes)
 
The problem seems to be the replace <br> with \r , but with out the <br> in the original text, I can not insert it with javascript ...

I can not seem to get any multiple line data to run through the script. so by useing <br> I can the paragraph into 1 line, even though it's 4 or 5 lines.


 
Hi guru97321:

I know this is an old post, but was wondering whether you resolved your problem.

I'm trying to figure out how I can replace data on an html page with data I'd like to retrieve from a mysql database.

I have about 30 fields on a html page that I want to change on the page after its loaded by clicking on an image.

I have this function working fine using an array creating in the header (javascript)on the page, but I need to be able to pull from a database, namely mysql.

Any help would be greatly appreciated.

Thanks,

Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top