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

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.
tech_questionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikoshaCommented:
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
peh803Commented:
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
mikoshaCommented:
Another good approach ,peh803 :)
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

peh803Commented:
:-) 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
tech_questionAuthor Commented:
peh803,

the problem is I have too many select boxes , this would become to maintain state for select boxes , right?
0
peh803Commented:
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
tech_questionAuthor Commented:
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
rg20Commented:
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
tech_questionAuthor Commented:
how can I populate request varaibles for a select box which has multiple select options ?
0
rg20Commented:
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
tech_questionAuthor Commented:
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
peh803Commented:
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
rg20Commented:
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
mikoshaCommented:
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
peh803Commented:
Here's a quick running example of how to maintain the state of multiple select boxes.

Regards,
peh803 (post coming directly after this...)
0
peh803Commented:
<%
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
peh803Commented:
@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
mikoshaCommented:
thanx, peh803
we could work as a team ,eh :)
0
tech_questionAuthor Commented:
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
peh803Commented:
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
peh803Commented:
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
peh803Commented:
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
tech_questionAuthor Commented:
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
peh803Commented:
Please post your current code.

Thanks!
peh803
0
tech_questionAuthor Commented:
       <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
peh803Commented:
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
tech_questionAuthor Commented:
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
peh803Commented:
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
peh803Commented:
do you have this application online where I could take a look at it?
0
tech_questionAuthor Commented:
0
peh803Commented:
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
tech_questionAuthor Commented:
pen803 it works now , removing of server.htmlencode did the trick
!~
0
peh803Commented:
Great! Glad to hear it!

Anything else I can give you a hand with then?

Thanks,
peh803
0
tech_questionAuthor Commented:
can I make this a more general function so that other select boxes can also be called?
0
peh803Commented:
sure, you can write a "getMultiSelectBox" function....something like this:

(post coming....)

peh803
0
peh803Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peh803Commented:
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
peh803Commented:
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
tech_questionAuthor Commented:
great! Perfect !
0
peh803Commented:
Glad I could give you a hand with it!

Regards,
peh803
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.