[program-java] Re: OT - Javascript question?

  • From: "William & Pamela " <pmcoats00@xxxxxxx>
  • To: <program-java@xxxxxxxxxxxxx>
  • Date: Sun, 10 Apr 2011 14:01:50 -0400

Hi Adrian, 

 

I believe we are using the onKeyUp event. That is actually when I noticed
the issue I'm currently having. I was doing testing as a result of a change
to the onKeyUp event, (see below info). 

 

Previous to the onKeyUp change we couldn't left arrow through the edit field
and make any changes. The cursor remained at the end of the field. 

If we wanted to make any changes to a character earlier in the field we
would have to backspace all the way back to the position we wanted to make
the change, in effect deleting everything up to the cursor position we
wanted to edit. 

Below is the change we made to the onKeyUp event. 

 

----- 

The fix is to allow the user to be able to use the left arrow key rather
than back space on a field that is set to be uppercase.

Replace: 

onkeyup="uppercase(this);"

with: 

onkeyup="if (ignoreEdits(event)) {uppercase(this);}"

 

----- Function ignoreEdits ----- 

function ignoreEdits(event)

{

  var keyCode = event.keyCode;

  if (edits[keyCode])

  {

    return false;

  }

  return true;

}

 

Thanks, 

Pamela 

 

 

 

From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Adrian Beech
Sent: Saturday, April 09, 2011 10:51 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: OT - Javascript question? 

 

G'day Pamela,

 

I'm assuming the JS function is called with each key press?

 

If this is the case then the entire field value is being replaced with the
upper case equivalent therefore the cursor's position will move to the end
each time.

 

It's been a long time since I've done any JS work and cannot recall if the
language supports bitwise operators.  Where I'm going with that thought is
that you may be able to iterate through the string (within the field itself)
and apply a mask such that the 6th bit of those characters which match your
test is set to 0 thus changing the case from one state to the other.  This
method may not necessarily impact the position of the cursor as you're not
replacing the field's value -- though as I've not tested this the proof will
be in the cooking, etc, etc.

 

A possible, and probably easier approach, is to use an alternative event
handler which is triggered such that you have the ability to examine the key
codes and adjust  accordingly before it's past onto the next handler in the
chain.  If I recall there are OnKeyDown/OnKeyUp hooks for this sort of
thing.

 

Good luck.

 

Cheers.

AB

 

From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of William & Pamela 
Sent: Sunday, 10 April 2011 9:21 AM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: OT - Javascript question? 

 

Thanks, Roger. It happens with all JSPs. 

I'll try the all experts google search. 

It happens on all the other computers the rest of the team is using as well,
so I don't believe it is something in the bowels of my computer. 

 

Thanks again, 

Pamela 

 

 

From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Roger Woolgrove
Sent: Saturday, April 09, 2011 5:28 AM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: OT - Javascript question? 

 

Hi Pamela,

 

I have no idea why java script is doing this.  Does it happen in all jsp
files or only a few.  If only a few then there maybe a problem with the
script, if it happens to all then probably your settings or something
complicated in the bowels of the computer.

The all experts website is what I believe is an excellent resource
particularly with programmoing issues.

 

Roger

 

 

----- Original Message ----- 

From: William  <mailto:pmcoats00@xxxxxxx> & Pamela 

To: program-java@xxxxxxxxxxxxx 

Sent: Friday, April 08, 2011 8:38 PM

Subject: [program-java] Re: OT - Javascript question? 

 

I was pointed to the below JS as contributing to my problem, which I will
try to explain. 

 

When I need to edit or update a field by inserting a word in the middle of
the field, every time I enter 1 character the cursor jumps to the end of the
field and I have to keep moving the cursor back to the insertion point in
the middle of the field I'm editing. 

I have to keep doing this for every character I want to enter. 

I don't know JS that well, but any suggestions would be appreciated. 

I will look into Roger's suggestion of googling "sigte all experts" (don't
understand that google search exactly), 

and getting a copy of JS for dummies. 

 

Thanks, 

Pamela 

 

----- JavaScript code ----- 

 

function uppercase(textField)

{

if (textField.value == '')

{

return;

}

var val = textField.value;

var upper = '';

var len = val.length;

for (var i = 0; i < len; i++)

{

if (/^[a-z]{1}$/.test(val.charAt(i)))

{

upper += val.charAt(i).toUpperCase();

}

else

{

upper += val.charAt(i);

}

}

textField.value = upper;

}

 

----- 

 

 

From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Friday, April 08, 2011 8:00 AM
To: 'program-java@xxxxxxxxxxxxx'
Subject: [program-java] Re: OT - Javascript question? 

 

Well Java script is also part of this list so fire away.

 

Jim 

 


  _____  


From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of William & Pamela 
Sent: April 7, 2011 21:01
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: OT - Javascript question? 

I know this is for Java questions, so could someone knowledgable in
Javascript please contact me offline? 

My e-mail is: 

pmcoats00@xxxxxxx 

 

Thanks, 

Pamela 

 

Other related posts: