• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

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

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
questjava
Asked:
questjava
  • 10
  • 9
  • 4
2 Solutions
 
for_yanCommented:
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
 
questjavaAuthor Commented:
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
 
Hugh McCurdyCommented:

Try this instead

function mask(obj) {
var a=’’;
var endMask = obj.value.length - 4;
for(var i=0,;i<endMask;i++) {
a += "x";
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Hugh McCurdyCommented:
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
 
questjavaAuthor Commented:
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
 
questjavaAuthor Commented:
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
 
Hugh McCurdyCommented:
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
 
questjavaAuthor Commented:
<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
 
Hugh McCurdyCommented:
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
 
for_yanCommented:
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
 
Hugh McCurdyCommented:
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
 
Hugh McCurdyCommented:
Looks like for_yan and I are on the same page.  He's typing faster.... ;-)
0
 
questjavaAuthor Commented:
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
 
for_yanCommented:



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
 
Hugh McCurdyCommented:
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
 
Hugh McCurdyCommented:
I'd try what for_yan suggested first.
0
 
for_yanCommented:
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
 
questjavaAuthor Commented:
yes , If I add value ="XXX" then will it solve it ?

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

Thanks
0
 
Hugh McCurdyCommented:
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
 
questjavaAuthor Commented:
Thank You all , I will try your suggestions and will get back to you soon.
0
 
questjavaAuthor Commented:
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
 
Hugh McCurdyCommented:
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
 
questjavaAuthor Commented:
thank you
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 10
  • 9
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now