?
Solved

Need help in a JSP page and a Java script urgently ...please

Posted on 2011-09-17
24
Medium Priority
?
531 Views
Last Modified: 2013-11-24
Hello ,

I am struck with the script , I have to hide/mask SSN(a number or string) .I should only be displaying last four digits of that number.

<html:text property="ssn1" styleClass="clsForm" maxlength="3" size="3" uppercase="true" onkeyup="javascript:autoTab(this, 3, event);if(value.length==2){ssn2.focus();mask(this)}"/>  


please note its not a <input> tag its <html:text> and the value is displayed from database we are not entering it and value is read only.I want to know If I am calling mask(this) from correct place. I do not see any thing reflected on the page even after I have written the following java script

java script

function mask(obj) {
var a=’’;
var len = obj.value.length;
for(var i=0,;i<len;i++) {
a += "x";
}

obj.value = a;
}
can somebody correct this java script . if numbers are like 123456789 then i should display them as *****6789 (only last four visible)

Thanks
0
Comment
Question by:questjava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
  • 4
24 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 1000 total points
ID: 36554308
I think it should be something like that, but I
Do not rememeber javascript syntax exactly, I'll check when get to my computer
But you definitely need to check if your character is at vthe beginning of the SSN or if it is one of the last four characters and act differently depending on that:

function mask(obj) {
var a=’’;
var len = obj.value.length;
for(var i=0,;i<len;i++) {
if(i<len-4)
a += "*";
else a += obj.value.charAt(i);  
}

obj.value = a;
return obj;
}
0
 

Author Comment

by:questjava
ID: 36554319
SSN is divided like SSN1 , SSN2 , SSN 3 ...so I have to mask complete SSN1(len=3) , SSN2(len=2) but not SSN 3(len=4)


<html:text property="ssn1" styleClass="clsForm" maxlength="3" size="3" uppercase="true" onkeyup="javascript:autoTab(this, 3, event);if(value.length==2){ssn2.focus();mask(this)}"/>&nbsp;
                                                                                                                      <html:text property="ssn2" styleClass="clsForm" maxlength="2" size="2" uppercase="true" onkeyup="javascript:autoTab(this, 2, event);if(value.length==2){ssn3.focus();mask(this)}"/>&nbsp;
                                                                                                                      <html:text property="ssn3" styleClass="clsForm" maxlength="4" size="4" uppercase="true" />                                                                                                                
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554321

Try this instead

function mask(obj) {
var a=’’;
var endMask = obj.value.length - 4;
for(var i=0,;i<endMask;i++) {
a += "x";
}
0
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554325
Seems some people posted before me.  Still, is the SSN NNNNNNNNN or NNN-NN-NNNN

If NNN-NN-NNNN instead of -4 use -5.
0
 

Author Comment

by:questjava
ID: 36554327
It will not be len-4 as its len is only 3 for ssn1 please see the code I have posted.. Thanks in advance
0
 

Author Comment

by:questjava
ID: 36554332
I have divided it into SSN1 SSN2 and SSN3

and I am adding * or replacing digits of SSN1(len=3)  with * and same is with SSN2 (len=2) and I am not calling this mask function for SSN 3(len = 4)  as it has to display the last four
0
 
LVL 13

Assisted Solution

by:Hugh McCurdy
Hugh McCurdy earned 1000 total points
ID: 36554336
It appears you are getting the SSN in 3 variables.  Just mask all of SSN1 and SSN2 but don't mask SSN3.

Having said that, if you are keeping 3 variables and just want to represent the SSN in the form ****-**-1234 to the user, then simply output ****-**- followed by whatever is in SSN3.

Does that make sense to you?
0
 

Author Comment

by:questjava
ID: 36554343
<html:text property="ssn1" styleClass="clsForm" maxlength="3" size="3" uppercase="true" onkeyup="javascript:autoTab(this, 3, event);if(value.length==2){ssn2.focus();mask(this)}"/>&nbsp

    <html:text property="ssn2" styleClass="clsForm" maxlength="2" size="2" uppercase="true" onkeyup="javascript:autoTab(this, 2, event);if(value.length==2){ssn3.focus();mask(this)}"/>&nbsp;
 
 <html:text property="ssn3" styleClass="clsForm" maxlength="4" size="4" uppercase="true" />    


I have divided it into SSN1 SSN2 and SSN3

and I am adding * or replacing digits of SSN1(len=3)  with * and same is with SSN2 (len=2) and I am not calling this mask function for SSN 3(len = 4)  as it has to display the last four  
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554346
Follow up note.  Java and Javascript aren't the same language.  I asked a moderator to move this thread over to Javascript so more people can help.  (Assuming I haven't answered it and it appears maybe not.)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36554351
and if they already come to you split into three parts, why would not you just replace ssn1 and ssn2 with literal  "***" and "**" and leave ssn3 as it is without even calling any function?
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554353
You can make your function simpler although my Javascript is foggy at this point.  (My Java is clear.)

I don't think you need a function at all.  This might work

SSN1 = "***";
SSN2 = "**";

As I said, my JS is foggy so I could be wrong.  I don't think you need a function though.  Just a simple assignment since SSN1 is always 3 long and SSN2 is always 2 long.
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554356
Looks like for_yan and I are on the same page.  He's typing faster.... ;-)
0
 

Author Comment

by:questjava
ID: 36554368
I really appreciate your help ..can you also tell me how do I and where do I put SSN1=*** in my <html:txt tag > that I have posted ? I  want to know , How and where do I replace it ? Can I do it in my JSP page ?

because in other java classes using ssn they are creating a Hashmap ...so I cannot do in Java action or form class , I want to do it in JSP

Thanks
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36554386



perhaps you add value="xxx"  like that?

<html:text property="ssn1" styleClass="clsForm" maxlength="3" size="3" uppercase="true"  value="xxx" onkeyup="javascript:autoTab(this, 3, event);if(value.length==2){ssn2.focus();mask(this)}"/>
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554396
If I'm not mistaken (JS is rusty in my brain; I came here thinking Java but am trying to help anyway)

SSN1="***";

needs to be in a javascript area - between <script> and </script>
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554398
I'd try what for_yan suggested first.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36554399
If these are not input values as you sepcified above - then it is not very clear what rôle this onkeyup attribute is playing? I was thinking it convrets your characters into xxxx or asterisks as user types them
0
 

Author Comment

by:questjava
ID: 36554400
yes , If I add value ="XXX" then will it solve it ?

Then I dont think I should call mask(this) ?

Thanks
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36554421
Yes, don't call mask().  Try what for_yan suggested first.  If that doesn't work, try what I suggested.  If neither works, please ask for more help.  (However, my daughter has a soccer game coming up so I'll be away for a while.  However, for_yan seems to have better current understanding of Javascript.)
0
 

Author Comment

by:questjava
ID: 36554435
Thank You all , I will try your suggestions and will get back to you soon.
0
 

Author Comment

by:questjava
ID: 36560403
My JSP page is not responding to the changes that I am making , I am using this struts-html.tld library , its an old project   ? can somebody help me on this ?
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36561398
I don't know about that library.  I would try two things.

1. Open your error console or Javascript console.  Firefox has one.  Not sure which of the others do.

2. Include debugging statements using document.write().  

Often one of those approaches leads me to a solution when I'm debugging.  (I see something that isn't right and know where to focus).
0
 

Author Comment

by:questjava
ID: 36561492
thank you
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 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