473,659 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

remembering last position in textbox / textarea and returning to after post / reload

I've got this javascript routine (i found on google - thank you) in an
asp.net page that on page reload sets the cursor of a textbox to the
last line. It works great!

Using a similar concept, I have another application that uses a
textbox like an editor window and has a save and other buttons.
Problem is - when I save/post/reload, the textbox returns to cursor
the top again.

How can I preserve / save the exact cursor spot and return to the
exact same spot I was in before I saved.

Here's the javascript code that sets the spot to the bottom of the
text. It called from <body onload=

<<<code>>>>

function f(){
var d=document;
if(d.getElement ById){
var el=d.getElement ById("chat");
if(el && el.createTextRa nge){
var rng=el.createTe xtRange(),
pos=el.value.le ngth;
if(pos!=-1 && rng){
rng.moveStart(" character",pos+ 1);
rng.collapse();
rng.select();

}
}
}
}
<<<code>>>>

I am imagining I will need to likely call the javascript with register
from asp.net. I'm just wondering how I can return position values to
serverside to save as a session variable - if that's even the best
way. Also, not clear on javascript code.

Thanks. Any help or information is greatly appreciated!
Jul 20 '05 #1
3 11241
Hello. More on this.

I have a javascript function that returns the location of the cursor
in the textbox. That javascript code is right in the asp.net code.
I've also added the asp.net code to create the javascript call to
that function. It's not working and when I do a view source it's
creating the function call inside my form???

this is the asp.net code I added at the end of sub that called from
button's onclick.

Dim sb As New System.Text.Str ingBuilder()
sb.Append("<scr ipt language='JavaS cript'> getpos();")
sb.Append("</script"+chr(62) )
Page.RegisterSt artupScript("th escript",sb.ToS tring())

it's creating (from the view source):

code...
</textarea>
<input type="submit" name="edit" value="edit" id="edit" />
<script language='JavaS cript'> getpos();</script>

</form>

Should this code be executing when I submit the form?

Thanks.
Jul 20 '05 #2
closer... but stuck. (some of this code was collect from Google
sources thanks!)

The following two javascripts save and then restore current cursor
position in a textbox following form refreshes and submits. Problem is
it's far from exact as the cursor tends to slide (slightly) up or
down. I've tried adjusting the value of pos on putpos(), but can't get
it to leave the screen frozen in one spot following submits/saves like
a normal editor would. I'm thinking getpos() needs work. Or maybe all
of this is a waste of time as maybe there is some asp.net or
javascript function that preserve cursor position???

editor is the form
editwindow is the textbox
line is the field that sends/recieve cursor position between client
and server
pos is the cursor position
function putpos() is called in body onload=
function getpos() is called from a save(submit) button

Its proving to be a great example on how to marry client-side and
server-side

Thanks for any help!

<<code>>
function getpos() {
var ctrl=document.g etElementById(" editwindow");
var saveText = ctrl.value;
ctrl.focus();
var range = document.select ion.createRange ();
var weirdStr = String.fromChar Code(1);
range.text = weirdStr;
var pos = ctrl.value.inde xOf(weirdStr);
ctrl.value = saveText;
range = ctrl.createText Range();
range.move('cha racter', pos);
range.select();
editor.line.val ue=pos;
editor.submit() ;

}
function putpos(){

pos=<%=Session( "line")%>;
if (pos!=0){
var d=document;
if(d.getElement ById){
var el=d.getElement ById("editwindo w");
if(el && el.createTextRa nge){
var rng=el.createTe xtRange();
if(pos!=-1 && rng){
rng.moveStart(" character",pos) ;
rng.collapse();
rng.select();

}
}
}
}
}

</script>
Jul 20 '05 #3
No, it will not! If you want something like that, attach an client event
to the form so your code should look like this:

<form onsubmit="getpo s();">
...
</form>

-- Justin Lovell

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2624
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML: **************************************************************
1
1696
by: Ben | last post by:
I have a Tabular form bound to a table. The purpose of this form is to get times from a timer and record them in a field. The timer dumps the time automatically through a serial port. When the time is recorded it goes to the next record. Sometimes a user may have to skip a record and come back. All of this is no problem and works great. I have 3 buttons that will set any penalties in a record. The person just needs to hit a button to...
3
368
by: jason | last post by:
I've got this javascript routine (i found on google - thank you) in an asp.net page that on page reload sets the cursor of a textbox to the last line. It works great! Using a similar concept, I have another application that uses a textbox like an editor window and has a save and other buttons. Problem is - when I save/post/reload, the textbox returns to cursor the top again. How can I preserve / save the exact cursor spot and return...
4
1159
by: Bernie V | last post by:
Hi, I have a textarea with serval lines on a webform. When i select the textarea or use the tab, I can't position to the first line. It positions to the middle. Then I have to use the arrows to go to the first line. How can I solve this ? Thx in advance.
1
1773
by: mpaine | last post by:
I have read http://msdn2.microsoft.com/en-us/library/ms178472(VS.80).aspx and my interpretation is that custom events should be fired between Page_Load and Page_LoadComplete. When I run the following sample code, the custom events are always last. Why is that? Your help will be greatly appreciated! <%@ Page Language="VB" AutoEventWireup="false" Title="Test ASP.NET Life Cycle"
2
5866
by: blitzztriger | last post by:
Hello!! how do i insert values into mysql , after parsing a submiting textbox?? I made the arrays, so this should be a basic insertion of them in the db, but something is missing, or in the wrong place...can anyone help me?? i didnt made anything in the VALUES (unless the POST ), because i bet the error is there (yes, the arrays are missing): $sql = "INSERT INTO dgplanets ( ID, coords , player name , alliance , name , ground , orbit ,...
4
5558
by: Finn Stampe Mikkelsen | last post by:
Hi Is there any way to make the textbox property show html, like a textarea on a webpage would?? I have a webapplication that saves an textarea complete with html tags and everything... Now i'm coding a windows application to work with the same data and i need these data to be displayed on an windows form, like they would on the
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.