Knowledgebase Home Page  >  RapidSpell Web ASP.NET  >  Behavior Customization
Search the Knowledge Base
How can I have the spell checker check only the text box with focus?
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=80&catId=55

Options

Print this page
Email this to a friend
If you have multiple text boxes on a page, with one spell check button, and you want the button to launch to checker on the text box with focus the following is one way to acheive this.
 
Javascript doesn't have anyway to determine if a text box has focus, therefore you will need to add onfocus handlers to each text box, eg.
 
<asp:textbox id="TextBox1" runat="server" onfocus="setCurrentlyFocused(this)" ....
<asp:textbox id="TextBox2" runat="server" onfocus="setCurrentlyFocused(this)" ....
 
and then track it with.
 
<script>
var currentTB;
 
function setCurrentlyFocused(tb){
    currentTB = tb;
}
</script>
 
 
Next you must use the "custom" TextComponentInterface in your RapidSpellWebLauncher, and provide the custom interface
 
function RSCustomInterface(tbElementName){
 this.tbName = tbElementName;
 this.getText = getText;
 this.setText = setText;
 function getText(){
  return currentTB.value;
 }
 function setText(text){
  currentTB.value = text;
 }
}
 
 
Full code for the page is below.
 
 
 
 
<%@ Page language="c#" Codebehind="Focus.aspx.cs" AutoEventWireup="false" Inherits="RapidSpellWeb_Demo_CSharp.Focus" %>
<%@ Register TagPrefix="rapidspellweb" Namespace="Com.Keyoti.RapidSpell" Assembly="Keyoti.RapidSpellWeb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>UserDictionary</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  <script type="text/javascript">
var currentTB;
 
function setCurrentlyFocused(tb){
    currentTB = tb;
}
 

function RSCustomInterface(tbElementName){
this.tbName = tbElementName;
this.getText = getText;
this.setText = setText;
function getText(){
 return currentTB.value;
}
function setText(text){
 currentTB.value = text;
}
}
  </script>
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="UserDictionary" method="post" runat="server">
   <asp:TextBox id="TextBox1" onfocus="setCurrentlyFocused(this)" style="Z-INDEX: 101; LEFT: 21px; POSITION: absolute; TOP: 87px"
    runat="server" TextMode="MultiLine" Height="181px" Width="397px" Columns="60" Rows="10">
   
The current textboxx will be checked, this is #1   
</asp:TextBox>
   <asp:TextBox id="Textbox2" onfocus="setCurrentlyFocused(this)" style="Z-INDEX: 101; LEFT: 23px; POSITION: absolute; TOP: 284px"
    runat="server" TextMode="MultiLine" Height="181px" Width="397px" Columns="60" Rows="10">
   
The current textboxx will be checked, this is #2   
</asp:TextBox>
   <asp:HyperLink id="HyperLink1" style="Z-INDEX: 108; LEFT: 28px; POSITION: absolute; TOP: 489px"
    runat="server" NavigateUrl="default.aspx" Font-Names="Arial">Main Page</asp:HyperLink>
   <RapidSpellWeb:RapidSpellWebLauncher id="RapidSpellWebLauncher1" style="Z-INDEX: 102; LEFT: 285px; POSITION: absolute; TOP: 482px"
    runat="server" TextComponentName-Length="8" TextComponentName="TextBox1" RapidSpellWebPage-Length="10" RapidSpellWebPage="PopUp.aspx"
    TextComponentInterface="Custom">
    <Button BorderWidth="" BorderColor="" ForeColor="" BackColor="" Height="" Width="" CssClass=""
     type="button" value="Check Spelling"></Button>
   </RapidSpellWeb:RapidSpellWebLauncher>
   <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 21px; POSITION: absolute; TOP: 31px" runat="server"
    Font-Names="Arial"> Focus</asp:Label>
  </form>
 </body>
</HTML>
 
 
Note: You'll have to provide a message to the user if no box is currently focused.

Related Questions:

Attachments:

No attachments were found.