?
Solved

checking for duplicate email-id with the help of ASP and Java SCript?

Posted on 2004-11-16
40
Medium Priority
?
314 Views
Last Modified: 2008-03-03
Hi,

Here is my situation. I have to check for duplicate email-ids when people are registering from a particular page, I have to notify the user if the email-id is already registered. I want the users the to be notified with a message and should not be losing all the data that is entered. I did this before by storing  all this information in variables and retrieving them after submitting the data and checking with the database, but this particular page has enormous amount of data, it is just not practical to do that!

Is there a solution for this wherein I can check with the database if there is a duplicate email-id which exists , notify the user and still the information that was entered would not be lost!



thanks,

tech.
0
Comment
Question by:tech_question
  • 21
  • 12
  • 4
  • +1
40 Comments
 
LVL 4

Expert Comment

by:mikosha
ID: 12594803
You can use page in another frame that has zero height (kind of invisible for user) and submit a form to this frame ,run asp page that checks whatever you want and than generates javascript code to call a javascript function in your original page in another farme that shows alert or changes some text (use top.frame_name.function_name()). That way yor original page will not be reloaded and all information will stay.

In case you're not using frames ,submit this to the ver-very small window (or not taht small, that will tell something like "Please wait ..." or somethig like that)  and do the same as from another frame (use opener.funtion_name())  
0
 
LVL 19

Expert Comment

by:peh803
ID: 12594809
Sure, you can do something like this:

1.) allow user to enter all information on the form
2.) write the page so it submits to itself
3.) write some ASP code that verifies whether or not the email is currently in use elsewhere or not / whether the email-id is a duplicate or not
4.) if the email IS duplicated, alert the user and do no more processing.  If you set up your inputs / textareas / select boxes correctly, it should be very easy to maintain the information that the user has entered.  Something like this is a suggested structure:

<input type="text" name="FirstName" id="FirstName" value="<%=server.htmlencode(request("FirstName"))%>">
<input type="text" name="LastName" id="LastName" value="<%=server.htmlencode(request("LastName"))%>">
<input type="text" name="EmailAddr" id="EmailAddr" value="<%=server.htmlencode(request("EmailAddr"))%>">

....etc.....

Hope this helps!
peh803
0
 
LVL 4

Expert Comment

by:mikosha
ID: 12594893
Another good approach ,peh803 :)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:peh803
ID: 12594914
:-) tyvm; I like yours, too.  It's really to you, tech!  They'll likely both work for you.  I'm happy to help come up with an example of what i'm talking about if you like..

peh803
0
 

Author Comment

by:tech_question
ID: 12595168
peh803,

the problem is I have too many select boxes , this would become to maintain state for select boxes , right?
0
 
LVL 19

Expert Comment

by:peh803
ID: 12595212
not particularly, as long as you do it using some kind of function.  Do you write your select boxes currently using some kind of function, or do you just use straight up HTML?

If you use HTML, I don't blame you for thinking it would be a whole lotta work; because it IS when you do that!  I hope you're not, though, because you're making more work for yourself than you need.

Let me know,
peh803
0
 

Author Comment

by:tech_question
ID: 12595493
peh803,

I use code to generate these select boxes, infact I get them from database. A user can select multiple values from these select boxes. Eg:         <select name="Fees" id="Fees"  multiple="true">
                                 
                                                
                                                <% do while not oFeesRecordset.EOF%>
                                                <option value<%=oFeesRecordset("FeeStructure")%>>
                                                <%=oFeesRecordset("FeeStructure")%></option>
                                                <%oFeesRecordset.MoveNext
                                                loop %>
                                    
                                                        </select>.


Could you please tell me how can I maintain state of this ?

0
 
LVL 9

Expert Comment

by:rg20
ID: 12595715
The best way I found to do this is to submit the page to itself, then the if the emails are valid
response.redirect to another accept page

if not all the values are in the request variables to repopulate the fields.  If you assign variables to the request variables, you won't get an error on the page when it is blank

0
 

Author Comment

by:tech_question
ID: 12596202
how can I populate request varaibles for a select box which has multiple select options ?
0
 
LVL 9

Expert Comment

by:rg20
ID: 12596245
requestSelect = Request("selectValue")

<select name="?">
<option value="whatever" <%if requestSelect = 'whatever' then%>selected<%end if%>
<option value="whatever2" <%if requestSelect = 'whatever2' then%>selected<%end if%>
</select>
0
 

Author Comment

by:tech_question
ID: 12596321
it is a multiple selectbox so many choices can be selected. What if a user selects three values from the select box? Also the select boxes values are generated from the database eg:

<select name="Fees" id="Fees"  multiple="true">
                                 
                                       
                                        <% do while not oFeesRecordset.EOF%>
                                        <option value<%=oFeesRecordset("FeeStructure")%>>
                                        <%=oFeesRecordset("FeeStructure")%></option>
                                        <%oFeesRecordset.MoveNext
                                        loop %>
                             
                                                    </select>.
0
 
LVL 19

Expert Comment

by:peh803
ID: 12596460
when you get the values out of a multiple select list, they are comma delimited, correct?  So, you should be able to do something like this:

<select name="Fees" id="Fees"  multiple="true">

<%
  Dim vSelectedItems
  Dim vFilteredArray
  vFilteredArray = ""
  vSelectedItems = ""
  if len(request("Fees"))>0 then
    vSelectedItems = split(request("Fees"), ",")
  end if  
  do while not oFeesRecordset.EOF
    sSelected = ""
    if isArray(vSelectedItems) then
      vFilteredArray = filter(vSelectedItems,oFeesRecordset("FeeStructure"))
      if len(trim(vFilteredArray(0)))>0 then
        sSelected = " selected "
      end if
    end if
%>
    <option <%=sSelected%> value="<%=oFeesRecordset("FeeStructure")%>">
    <%=oFeesRecordset("FeeStructure")%></option>
<%
    oFeesRecordset.MoveNext
  loop %>
                             
</select>

HTH,
peh803
0
 
LVL 9

Expert Comment

by:rg20
ID: 12596516
I know that your question is for jscript but you might try to use this philosiphy in your code

http://www.tek-tips.com/viewthread.cfm?qid=787865&page=5
0
 
LVL 4

Expert Comment

by:mikosha
ID: 12596519
Ok, I have to clear myself a little, because this regards to more general question about programming style (as I see this).
By my opinion it' a good idea to separate presentation and logic. ASP thou , let you place a code inside html (logic inside presentation) that makes your code less readable and even working little slower (because IIS renderes all html tags in asp page and transfers them to response.write directives before rendering asp code. second thing - asp precompilation with precompilatioin cashing ,that not always works smoothly with pure asp code, here is not avalabe at all). So, my suggestion was given with all this in mind. In your case you can write separate asp page with server-side code only for validation and updating a db. I see that you're  using  "spagetti" stile already, so may be it will be a start point when you'll reconsider this programming style. Server-side(asp) and client-side(javascript and html) separtion has many other advantages (if you''l decide to move your app to .net it will go much better than "spagetti", you can write more "object-oriented"-style code using asp classes and so on...) .

It's not something personal ,just friendly suggestion:)

P.S when i sturted to use asp ,a long-long time ago, i used this style too and did not want to switch to smothing else,but fact are talking for themselfs...even if it takes a little longer to orginize your code , once it'll be orginized you'll fill the diference:)
0
 
LVL 19

Expert Comment

by:peh803
ID: 12596650
Here's a quick running example of how to maintain the state of multiple select boxes.

Regards,
peh803 (post coming directly after this...)
0
 
LVL 19

Expert Comment

by:peh803
ID: 12596652
<%
Dim vSports
Dim i
vSports = Array("Baseball", "Basketball", "Soccer", "Football", "Ping Pong", "Bass Fishing")
Dim vSelectedItems
Dim vFilteredArray

vFilteredArray = ""
vSelectedItems = ""
  if len(request("sports"))>0 then
    vSelectedItems = split(request("sports"), ",")
  end if  

%>
<form name=mult method=post>
  <select multiple name="sports" size=6>
  <%
  for i=0 to ubound(vSports)
    sSelected = ""
    if isArray(vSelectedItems) then
      vFilteredArray = filter(vSelectedItems,vSports(i))
      if ubound(vFilteredArray)>=0 then
        sSelected = " selected "
      end if
    end if
  %>
    <option <%=sSelected%> value="<%=vSports(i)%>"><%=vSports(i)%></option>
  <%
  next
  %>
  </select>
  <BR>
  <input type=submit name=submit value=submit>
</form>
0
 
LVL 19

Expert Comment

by:peh803
ID: 12596679
@mikosha -- a lot of good points.  Generally, I will do this very thing, separating the logic, etc.  These are all good points that @tech_question would be wise to consider.  

tech_question -- while my method will work for maintaining the state of a multiple select box in ASP / HTML, mikosha is correct; you'll see many huge advantages if you move to ASP.Net and / or if you implement a practice of separating presentation and code logic.  

My answer, in the mean time, should get you where you want to be.

peh803
0
 
LVL 4

Expert Comment

by:mikosha
ID: 12597124
thanx, peh803
we could work as a team ,eh :)
0
 

Author Comment

by:tech_question
ID: 12597360
peh803,

I am using the solution you suggested at 10:10 AM but when I submit the data nothing is poping up , the entire select box is null!
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597381
yeah, I tested it and I had some stuff that was incorrect...please restructure your code to look like my 2nd example.  Let me know if you have other questions about it!

Thanks,
peh803
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597395
actually, to make it easier on you, here's the fixed code:

<%
  Dim vSelectedItems
  Dim vFilteredArray
  vFilteredArray = ""
  vSelectedItems = ""
  if len(request("Fees"))>0 then
    vSelectedItems = split(request("Fees"), ",")
  end if  
  do while not oFeesRecordset.EOF
    sSelected = ""
    if isArray(vSelectedItems) then
      vFilteredArray = filter(vSelectedItems,oFeesRecordset("FeeStructure"))
      if ubound(vFilteredArray)>=0 then
        sSelected = " selected "
      end if
    end if
%>
    <option <%=sSelected%> value="<%=oFeesRecordset("FeeStructure")%>">
    <%=oFeesRecordset("FeeStructure")%></option>
<%
    oFeesRecordset.MoveNext
  loop %>

Hope this helps!
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597421
by the way, if you view the source for the page with the blank multiple select box, you will find that an error is actually being generated "behind the scenes" and is being written out to the source of the page (but not being displayed to the user).  Right click --> view source will show you that, using my old, incorrect code, you're getting a subscript out of range [0] error.  Something like that.  Just for your info...

Anyways, you should be able to get rid of this problem by modifying the code as stated above.

Thanks,
peh803
0
 

Author Comment

by:tech_question
ID: 12597555
peh803, a small glitch the code does not work when we select options which include a space such as

if the select box does include "advertising & commercials", this is not selected when we post the data !

0
 
LVL 19

Expert Comment

by:peh803
ID: 12597599
Please post your current code.

Thanks!
peh803
0
 

Author Comment

by:tech_question
ID: 12597636
       <select name="Subjects" id="Subjects"  multiple="true">
                                 
                                          <%       
                                         if len(server.HTMLEncode(request("Subjects")))>0 then
                                            selectedsubjs = split(server.htmlencode(request("Subjects")),",")
                                           
                                          end if
                                                                            
                                                 do while not oSubjectRecordset.EOF
                                                sSelected = ""
                                                        if isArray(selectedsubjs) then
                                                           vFilteredArray = filter(selectedsubjs,oSubjectRecordset("Subject"))
                                                               'if len(trim(vFilteredArray(0)))>0 then
                                                           if ubound(vFilteredArray)>=0 then
                                                                  sSelected = " selected "
                                                              end if
                                                  end if
                                                %>
                                                                                          
                                                <option <%=sSelected%> value<%=oSubjectRecordset("Subject")%>>
                                                <%=oSubjectRecordset("Subject")%></option>
                                                <%oSubjectRecordset.MoveNext
                                                loop %>
                                    
                                                        </select>
                                          
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597658
this line:
   <option <%=sSelected%> value<%=oSubjectRecordset("Subject")%>>

Shouldn't it be like this?
   <option <%=sSelected%> value="<%=oSubjectRecordset("Subject")%>">

Let me know if that helps at all...
0
 

Author Comment

by:tech_question
ID: 12597702
did not work. All options which contain a space and an appersand are not selected but I guess the problem is with the space!

Eg: "Advertising & Commercials" is not selected.


0
 
LVL 19

Expert Comment

by:peh803
ID: 12597717
okay, another thing...why use server.htmlencode here?
  if len(server.HTMLEncode(request("Subjects")))>0 then
    selectedsubjs = split(server.htmlencode(request("Subjects")),",")
  end if

Try it without:
  if len(request("Subjects"))>0 then
    selectedsubjs = split(request("Subjects"),",")
  end if

The space shouldn't be a problem for you...
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597721
do you have this application online where I could take a look at it?
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597760
okay, and what's an example of an email address that is current in your system, so I can duplicate the post back / non persisted data in the multiple select?
0
 

Author Comment

by:tech_question
ID: 12597761
pen803 it works now , removing of server.htmlencode did the trick
!~
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597768
Great! Glad to hear it!

Anything else I can give you a hand with then?

Thanks,
peh803
0
 

Author Comment

by:tech_question
ID: 12597791
can I make this a more general function so that other select boxes can also be called?
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597806
sure, you can write a "getMultiSelectBox" function....something like this:

(post coming....)

peh803
0
 
LVL 19

Accepted Solution

by:
peh803 earned 2000 total points
ID: 12597866
function getSelectBox(sSelectNameAndID, _
                      sSelectedValues, _
                      rsSourceData, _
                      sRecordsetFieldName)
  Dim sRetVal
  Dim vSelectedItemArray
  Dim sSelected
  Dim vFilteredArray
  sRetVal = "<select name=""" & sSelectNameAndID & """ id=""" & sSelectNameAndID & """ multiple=""true""> " & vbCrLf

  if len(sSelectedValues)>0 then
    vSelectedItemArray = split(sSelectedValues,",")
  end if
                                                             
  do while not rsSourceData.EOF
  sSelected = ""
  if isArray(vSelectedItemArray) then
    vFilteredArray = filter(vSelectedItemArray,rsSourceData(sRecordsetFieldName))
    if ubound(vFilteredArray)>=0 then
      sSelected = " selected "
    end if
  end if
  sRetVal = sRetVal & "<option " & sSelected & " value=""" & rsSourceData(sRecordsetFieldName) & """>" & vbCrLf
    sRetVal = sRetVal & rsSourceData(sRecordsetFieldName) & "</option>" & vbCrLf
  rsSourceData.MoveNext
  loop
  sRetVal = sRetVal & "</select>"
  getSelectBox = sRetVal
end function
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597884
Then, to call it using your stuff from above, you'd do something like this:

response.write getSelectBox("Subjects", _
                                           request("Subjects"), _
                                           oSubjectRecordset, _
                                           "Subjects")

Hope this helps!

peh803
0
 
LVL 19

Expert Comment

by:peh803
ID: 12597913
also, you might consider calling the function "getMultiSelectBox" instead; that way, you'll know which kind of select box you're generating.  Alternatively, you could add a few function parameters and make your function smart enough to generate both multi-selects and drop down selects...the possibilities are endless! :)

HTH,
peh803
0
 

Author Comment

by:tech_question
ID: 12598081
great! Perfect !
0
 
LVL 19

Expert Comment

by:peh803
ID: 12598119
Glad I could give you a hand with it!

Regards,
peh803
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

840 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