Solved

Activate 'overwrite'-mode with JScript

Posted on 2000-04-10
7
746 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
ID: 2701182
Unfortunatly this is impossible in JavaScript, The creators feel it would be a security risk. Sorry
0
 

Author Comment

by:mnprsd
ID: 2707421
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
ID: 2707970
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:mnprsd
ID: 2710798
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
ID: 2710904
Does make a difference!

Michel
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 150 total points
ID: 2737299
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
ID: 2746475
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

809 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