473,406 Members | 2,217 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,406 software developers and data experts.

writing to a coordinate in a textarea

132 100+
Hello everyone,

I've been browsing the net for some time now and I can't find the answer I'm looking for.


I'm trying to insert text in a textarea but at a specified place. 30 characters from the left side of the textarea. But I can't find that script.

What I did found were scripts to insert text at the cursor. The caret position was saved in a variable and then new text inserted at that caret-position. However, I would like to specify the location in the script. Anybody knows how to achieve this?

Thanks,

Cainnech
Jan 8 '08 #1
6 1540
mrhoo
428 256MB
Expand|Select|Wrap|Line Numbers
  1. var str=' String to insert';
  2. var n=30;
  3. var val= textareareference.value;
  4. textareareference.value= val.substring(0,n)+ str+ val.substring(n);
  5.  
Jan 8 '08 #2
Cainnech
132 100+
Hi MrHoo,

I've tried the code but it doesn't seem to work. On the net I found not really that much information about it. Could you explain me how the textareareference works ?

Thanks,

Cainnech
Jan 8 '08 #3
mrhoo
428 256MB
Excuse me- when I said textareareference, I meant
'put a reference to the textarea here'-
for example, if you had one textarea on the page you could use
document.getElementsByTagName('textarea')[0],
or if it had an id of 'mytext' it could be
document.getElementById('mytext').
Jan 8 '08 #4
Cainnech
132 100+
Hi Mrhoo,

Silly me, I didn't think of it that way :-)

I tested it, and it writes the code into the textarea except it writes it in theleft corner and not at the 30th character. Am I doing something wrong?

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <SCRIPT>
  4.  
  5. function execute(){
  6. var str='This is a test';
  7. var n=30;
  8. var val = document.form.output.value;
  9. document.form.output.value += val.substring(0,n)+ str + val.substring(n);
  10. }
  11. </SCRIPT>
  12.  
  13. </HEAD>
  14. <BODY>
  15. <form name="form">
  16. <textarea name="output" cols="50" rows="15"></textarea>
  17. <br>
  18. <input type="button" value="Test it" onclick="execute()">
  19. <input type="reset" value="reset">
  20. </form>
  21. </BODY>
  22. </HTML>
  23.  
Jan 8 '08 #5
mrhoo
428 256MB
If you do not have 30 characters you need to insert them-
and don't use += to set the value here.

<HTML>
<HEAD>
<SCRIPT>

Expand|Select|Wrap|Line Numbers
  1. function execute(){
  2.     var str= 'This is a test';
  3.     var n= 30;
  4.     var who= document.getElementsByName('output')[0];
  5.     var val= who.value;
  6.     while(val.length<n)val= ' '+ val;
  7.     who.value= val.substring(0,n)+' '+ str + ' '+
  8.     val.substring(n);
  9. }
</SCRIPT>

</HEAD>
<BODY>
<form>
<textarea name="output" cols="50" rows="15"></textarea>
<br>
<input type="button" value="Test it" onclick="execute()">
<input type="reset" value="reset">
</form>
</BODY>
</HTML>
Jan 8 '08 #6
Cainnech
132 100+
Thanks mrhoo,

That works indeed. Except I just came to realise that this probably isn't the right approach for my purpose because I need to put it on every line.

You see I'm generating an output in the textarea and a part of that output I want to align to character 30 just so the contents are clear and structured.

I'll have to experiment further to make it work I think.

But thanks for the help you've given me.

Cainnech
Jan 8 '08 #7

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

Similar topics

4
by: Csaba Gabor | last post by:
What I'd like to do is to be able to set the font of a textarea element to the same font that another element is using (say, for example, an <INPUT type=text ...> element, but if that's a no go,...
1
by: Volt | last post by:
is there any way to select and mark part of text in textarea by regular expression? i need to select the first string in textarea whitch is like xxxxx,xxx where x is any character
4
by: TJS | last post by:
can the rows and columns of a textarea element with an id be changed on the fly ? if so is there an example ?
12
by: Von Clubusev | last post by:
I like Java just as much as I like C#, but the truth is that unless you absolutely need platform portability, DotNet is the way to go. This is becoming even more true with the release of Windows...
6
by: HaggMan | last post by:
I'm creating a page that: - accepts user input in whatever language - saves that input to a file - reads the file and displays the original input The following code successfully writes the user...
0
by: peradino | last post by:
Hi I have a problem when I want to know how far my cursor is from the top of pictureBox. I can get mouse coordinate but it is screen coordinate. I can get the top position of my pictureBox...
9
by: Eric.Gabrielson | last post by:
Hello, I am very knew to python and am attempting to write a program in python that a friend of mine is having to write in java. I am doing this for fun and would like some help as to how i can...
5
by: fredb | last post by:
I am trying to write data from my database to a html textarea. I can write the data with the php print function. Below is the code. Any help you can offer is greatly appreciated. Thanks,...
0
by: jigsmshah | last post by:
I need to print a text file .When i print it ,it is not printed exactly form 0,0 coordiante of the page. I mean the top most left corner.It is leaving some margin from top and from left.The code is...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
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...
0
agi2029
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,...
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.