Solved

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

Posted on 2011-09-17
24
498 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
  • 10
  • 9
  • 4
24 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility

Try this instead

function mask(obj) {
var a=’’;
var endMask = obj.value.length - 4;
for(var i=0,;i<endMask;i++) {
a += "x";
}
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
Comment Utility
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
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

Expert Comment

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

Author Comment

by:questjava
Comment Utility
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
Comment Utility



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
Comment Utility
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
Comment Utility
I'd try what for_yan suggested first.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank You all , I will try your suggestions and will get back to you soon.
0
 

Author Comment

by:questjava
Comment Utility
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
Comment Utility
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
Comment Utility
thank you
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

728 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

14 Experts available now in Live!

Get 1:1 Help Now