Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #9801

Re: Input Controls

From "Mel Smith" <med_cutout_syntel@aol.com>
Newsgroups comp.lang.javascript
Subject Re: Input Controls
Date 2011-12-30 10:49 -0700
Message-ID <9m6bteFti4U1@mid.individual.net> (permalink)
References <sk5qf7h79vi3f5v6u1rnapq4t5e5020h8d@4ax.com>

Show all headers | View raw


Gene said:

">
>  1) Position to a particular point in a control's value.  For
> example, if entering a date, it could be much more user-friendly if,
> when the control gets focus, the cursor were positioned just before
> the days as in:
>          201112@29
> where the at-sign represents the cursor.  (In my app-to-be, the date
> is usually in the current month, but not always.)

Hi Gene:

    I picked up and slightly modified the xhtml code below. Maybe you will 
find it useful for positioning your cursor in the middle of a textarea:

HTH
-Mel Smith

********************
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<title>Position Cursor in Textarea block</title>

<script type="text/javascript">

function setCursor(el,st,end) {
 if(el.setSelectionRange) {
  el.focus(); el.setSelectionRange(st,end);
  }
 else {
  if(el.createTextRange) {
   range=el.createTextRange();
   range.collapse(true);
   range.moveEnd('character',end);
   range.moveStart('character',st);
   range.select();
   }
  }
 }
</script>
</head>
<body onload="setCursor(document.getElementById('input1'),13,13);" >
<div>
 <textarea id="input1" name="input1" rows="10" cols="30">Happy kittens 
dancing</textarea>
</div>
</body>
</html>
**********************

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Input Controls Gene Wirchenko <genew@ocis.net> - 2011-12-29 18:11 -0800
  Re: Input Controls Norman Peelman <npeelmandog@cfl.rr.com> - 2011-12-30 06:40 -0500
  Re: Input Controls Martin Honnen <mahotrash@yahoo.de> - 2011-12-30 12:57 +0100
  Re: Input Controls "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-30 10:49 -0700
  Re: Input Controls RobG <rgqld@iinet.net.au> - 2011-12-31 15:21 -0800

csiph-web