Solved

Activate 'overwrite'-mode with JScript

Posted on 2000-04-10
7
743 Views
Last Modified: 2012-05-04
Does anybody know a way to activate/deactivate the overwritemode (insert-key toggle) within a textbox, with JScript in IE.

0
Comment
Question by:mnprsd
7 Comments
 

Expert Comment

by:Deathead
Comment Utility
Unfortunatly this is impossible in JavaScript, The creators feel it would be a security risk. Sorry
0
 

Author Comment

by:mnprsd
Comment Utility
Sad! Here is my problem. I have a textbox with initially five hyphens in it ("-----"). Each of these hyphens represents a flag. The value can be any number from 0 to 9, or -. For example "--1-2".

The users will often change these values and therefore I wanted to initially set the the textbox in overwrite-mode.

If anyone have any great workaround for this problem I'd be happy to know.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
How about 5 dropdowns???
<select name=s1>
<option value="-">-
<option value=0>0
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select><select name=s2>
<option value="-">-
<option value=0>0
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select><select name=s3>
<option value="-">-
<option value=0>0
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select><select name=s4>
<option value="-">-
<option value=0>0
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select><select name=s5>
<option value="-">-
<option value=0>0
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
<option value=9>9
</select>

Michel
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:mnprsd
Comment Utility
Unfortunately, this textbox isn't the only one. There are four of these textboxes per row, and there can be multiple rows, sometimes over a hundred. Sorry, but I forgot to mention that.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Does make a difference!

Michel
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 150 total points
Comment Utility
You can intercept a keydown and change it to an INSERT key, but that just toggles the state.  The following code uses TEXTAREA to simulate inputs.  You need five of them, but as shown, they take very little more space than a 5-clm text input.

To make the TEXTAREA simulation work, it selects the entire field on focus, then discards any non-visible characters on blur.

I also added a flourish: It validates each incoming character.

Your submit function would need to collect all the inputs but that should be simple since they are guaranteed to be valid and each id exactly one-character long.

<html>
<SCRIPT>
//----------- written by Dan Rollins
//----------- some real-time data validation
function DoKeyPress() {
    var nCode= window.event.keyCode;
    if ((nCode==45) || ((nCode>=48) && (nCode<=57)) ) {
        //no problem
    }
    else {
          alert("Please enter value between 0 and 9 or -" );
            window.event.keyCode= 0; // cancel the character
    }
}
//---------- make TextArea more like < INPUT TYPE=text>
function DoOnFocus( oInput ) {
        oInput.select();
}
//---------- parm check, removes all but the final character (the one that is visible)
function DoOnBlur(oInput) {
      var s= "-"+oInput.value;
      oInput.value= s.substr(s.length-1,1);
}
</SCRIPT>

Item 1:
<TEXTAREA STYLE="overflow:hidden" ID=Fld00_0 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >1</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld00_1 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >2</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld00_2 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >3</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld00_3 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >4</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld00_4 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >5</TEXTAREA>
&nbsp;&nbsp;Item 2:
<TEXTAREA STYLE="overflow:hidden" ID=Fld01_0 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >1</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld01_1 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >2</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld01_2 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >3</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld01_3 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >4</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld01_4 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >5</TEXTAREA>
&nbsp;&nbsp;Item 3:
<TEXTAREA STYLE="overflow:hidden" ID=Fld02_0 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >1</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld02_1 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >2</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld02_2 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >3</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld02_3 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >4</TEXTAREA>
<TEXTAREA STYLE="overflow:hidden" ID=Fld02_4 ROWS=1 COLS=1 onfocus="DoOnFocus(this)"  onblur="DoOnBlur(this) "onkeypress="DoKeyPress()" >5</TEXTAREA>

<html>


0
 

Author Comment

by:mnprsd
Comment Utility
This solution actually works!! Maybe not as pretty as I had hoped it could be, but still working and the user shouldn't notice any lack in functionality! I will also add a feature that sets focus to the next <textarea> whenever a valid key is pressed. Thanks man!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 41
indexOf() 2d array value 2 38
Problem to Popup 2 48
Re-position the objects 7 46
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now