html - Disable button if txtbox validates -
edit
solved! @peter campbell pointing me in right direction (and doing of leg work me there). code changed this:
if string.isnullorempty(output) exists = false else exists = true end if if string.isnullorempty(output) return string.empty dim c gpcuser if typeof httpcontext.current.session("customer") gpcuser c = ctype(httpcontext.current.session("customer"), gpcuser) if c.accountno > 0 return "" end if
by moving if statement sets 'exists' boolean before return statements, still fire correctly , validate emails properly, correctly disable button well.
end edit
i have page checks customer's email address see if it's in our database. if is, page should ask customer log-in email instead of continuing new account, doesn't prevent them continuing.
i disable continue button if email address in system can't figure out (i'm store's new web developer , there no documentation me existing site).
code below,
<%@ page language="vb" masterpagefile="~/standard-no-menu.master" autoeventwireup="false" codefile="billing-details.aspx.vb" inherits="billing_details" %>
"); --> "); -->
<script language="javascript" type="text/javascript"> function validateform() { if(document.getelementbyid('<%= lstpaymentoptions.clientid %>').selectedindex == "0") { alert("please select \"payment method\"."); document.getelementbyid('<%= lstpaymentoptions.clientid %>').focus(); return (false); } if (aforgotpwd.style.display != null && aforgotpwd.style.display.tostring() != "none") { var emailele = document.getelementbyid("<%= txtemail.clientid %>"); emailele.focus(); return false; } if(document.getelementbyid('<%= txtemail.clientid %>').value=="") { alert("please enter value in field \"email\"."); document.getelementbyid('<%= txtemail.clientid %>').focus(); return (false); } validemail=0; var checkstr = document.getelementbyid('<%= txtemail.clientid %>').value; (i = 0; < checkstr.length; i++) { if(checkstr.charat(i)=="@") validemail |= 1; if(checkstr.charat(i)==".") validemail |= 2; } if(validemail != 3) { alert("please enter valid email address."); document.getelementbyid('<%= txtemail.clientid %>').focus(); return (false); } if(document.getelementbyid('<%= txtfirstname.clientid %>').value=="") { alert("please enter value in field \"first name\"."); document.getelementbyid('<%= txtfirstname.clientid %>').focus(); return (false); } if(document.getelementbyid('<%= txtlastname.clientid %>').value=="") { alert("please enter value in field \"last name\"."); document.getelementbyid('<%= txtlastname.clientid %>').focus(); return (false); }</script> <asp:panel runat="server" defaultbutton="btncontinue"> <div class="billing-row"> <div class="cart-process-image"><img alt="" src="images/list_tick.gif"/></div> <div class="cart-process-text">shopping cart</div> <div class="cart-process-image"><img alt="" src="images/rightarrow.jpg"/></div> <div class="cart-process-text"><strong>personal , shipping details</strong></div> <div class="cart-process-image"><img alt="" src="images/rightarrow.jpg"/></div> <div class="cart-process-text">payment details</div> </div> <div class="billing-column-left"> <div class="billing-holder"> <div class="billing-row"> <p><strong>payment method</strong></p> <div class="billing-column-mandatory">*</div> <div class="billing-column-label">how pay?</div> <div class="billing-column-textbox"><asp:dropdownlist id="lstpaymentoptions" runat="server" appenddatabounditems="true" cssclass="drop-down-list"></asp:dropdownlist></div> <div><asp:requiredfieldvalidator id="paymentvalidator" runat="server" controltovalidate="lstpaymentoptions" errormessage="please select payment method" forecolor="red" initialvalue="please select"> </asp:requiredfieldvalidator></div> </div> </div> <div class="billing-row"> </div> <div class="billing-holder"> <p><strong>your contact details</strong></p> <div class="billing-row"> <div class="billing-column-mandatory"> </div> <div class="billing-column-label">company / account name: </div> <div class="billing-column-textbox"><asp:textbox name="txtaccountname" id="txtaccountname" maxlength="60" width="270" runat="server" cssclass="textbox"></asp:textbox></div> </div> <div class="billing-row"> <div class="billing-column-mandatory">*</div> <div class="billing-column-label">email: <asp:requiredfieldvalidator id="emailvalidator" runat="server" controltovalidate="txtemail" errormessage=" required" forecolor="red"> </asp:requiredfieldvalidator></div> <div class="billing-column-textbox"><asp:textbox id="txtemail" maxlength="60" width="270" runat="server" cssclass="textbox" autopostback="true"></asp:textbox><b><a id="aforgotpwd" href="/forgotten-password.aspx" style="display:none"> we have email address in our database. click here retrieve password?</a></b></div> </div> <div class="billing-row"> <div class="billing-column-mandatory">*</div> <div class="billing-column-label">first name: <asp:requiredfieldvalidator id="firstnamevalidator" runat="server" controltovalidate="txtfirstname" errormessage=" required" forecolor="red"> </asp:requiredfieldvalidator></div> <div class="billing-column-textbox"><asp:textbox name="txtfullname" id="txtfirstname" maxlength="30" width="270" runat="server" cssclass="textbox"></asp:textbox></div> </div> <div class="billing-row"> <div class="billing-column-mandatory">*</div> <div class="billing-column-label">last name: <asp:requiredfieldvalidator id="lastnamevalidator" runat="server" controltovalidate="txtlastname" errormessage=" required" forecolor="red"> </asp:requiredfieldvalidator></div> <div class="billing-column-textbox"><asp:textbox name="txtfullname" id="txtlastname" maxlength="30" width="270" runat="server" cssclass="textbox"></asp:textbox></div> </div> <div class="billing-holder"> <p><strong>additional information relating order.</strong></p> <div class="billing-column-textfield"><asp:textbox textmode="multiline" width="463" height="212" runat="server" id="txtadditionalinfo" cssclass="textbox"></asp:textbox></div> </div> </div> <asp:panel id="pnlverticalresponse" runat="server" visible="false"> <div class="billing-oos-background"> <div class="billing-row"> <asp:label id="lblsubscribe" runat="server" text="<p><strong>you not subscribed our newsletter:</strong>"></asp:label></div> <div class="billing-row"><asp:checkbox id="chksubscribe" runat="server" /> receive information , promotional material global pc</div></div> </asp:panel> <asp:panel id="pnloutofstockblurb" runat="server" visible="false" > <div class="billing-oos-background"><div class="billing-row"><asp:label id="lbloutofstockmessage" runat="server" text="<strong>items out of stock:</strong><p>you have ordered 1 or more items out of stock. normal procedure global pc hold order until items in stock , ship entire order @ once. however, if wish can elect have order split 2 shipments out of stock items arriving @ later date. order split 2 shipments?</p>"></asp:label></div> <div class="billing-row"><asp:radiobuttonlist id="radlistsplit" runat="server" cellspacing="5" autopostback="true" causesvalidation="true" onselectedindexchanged="radlistsplit_selectedindexchanged" cssclass="textbox" borderwidth="0px"><asp:listitem value="0" text="yes, want recieve order 2 separate deliveries"></asp:listitem><asp:listitem value="1" text="no, want wait , receive items @ once"></asp:listitem></asp:radiobuttonlist> <asp:requiredfieldvalidator id="splitvalidator" runat="server" controltovalidate="radlistsplit" errormessage="please select 1 shipping option" forecolor="red"> </asp:requiredfieldvalidator> </div></div></asp:panel> <div class="billing-row"> <div class="billing-button-cart"> <div class="green-button"> <a href="cart.aspx">back cart</a> </div> </div> <div class="billing-button-checkout"> <div class="green-button"> <asp:linkbutton text="checkout" onclientclick="return validateform();" runat="server" id="btncontinue" /> </div> </div> </div> </asp:panel> </asp:content>
vb.net
imports dataaccesslayer imports system.net imports system.data imports system.net.mail imports com.verticalresponse.api partial class billing_details inherits system.web.ui.page protected c gpcuser dim ismember boolean = false dim bemember boolean = false shared exists boolean = false protected sub page_load(byval sender object, byval e system.eventargs) handles me.load master.page.title += " - checkout" dim listid integer dim sessionid integer dim vruser new vrapi() dim newsession new loginargs() newsession.username = "******@********.co.nz" ' verticalresponse username newsession.password = "**********" 'your verticalresponse password ' objla.impersonate_user = "subaccount@emailaddress.com"; // if accessing or acting subaccount, uncomment , replace applicable email address. newsession.session_duration_minutes = "120" dim [date] datetime = datetime.now listid = 284662333 if typeof session("customer") gpcuser c = ctype(session("customer"), gpcuser) else c = new gpcuser end if if c.cartobjects.count <= 0 response.redirect("cart.aspx") end if if not page.ispostback ' check shipping see if delivery details need displayed if c.shippingmethodname "*pick-up*" pnlshippingdetails.visible = false end if 'check if customer has ordered out of stock items if c.intoutofstockitems >= 1 pnloutofstockblurb.visible = true else pnloutofstockblurb.visible = false end if txtemail.attributes.add("onblur", cstr(iif(c.accountno > 0, "", "callme(this.id,this.id);"))) lstpaymentoptions.datasource = sqlhelper.executedataset(system.configuration.configurationmanager.appsettings("dbconn"), "xw_getpaymenttypes").tables(0) lstpaymentoptions.datatextfield = "ptdesc" lstpaymentoptions.datavaluefield = "ptno" lstpaymentoptions.items.insert(0, "please select") 'lstpaymentoptions.databind() if c.customerid > 0 'populate table txtaccountname.text = c.accountname txtfirstname.text = c.firstname txtlastname.text = c.lastname txtemail.text = c.email txtaddress.text = c.address txtcitytown.text = c.city txtsuburb.text = c.suburb txtpostcode.text = c.postcode txtphone.text = c.phone txtmobile.text = c.mobile try sessionid = vruser.login(newsession) catch ex system.exception 'lblmessage.text = ex.tostring() end try dim getmember new getlistmemberbyemailaddressargs() getmember.session_id = sessionid getmember.list_id = listid getmember.email_address = txtemail.text try vruser.getlistmemberbyemailaddress(getmember) ismember = true pnlverticalresponse.visible = false catch ex system.exception ismember = false pnlverticalresponse.visible = true end try if (ismember = false) pnlverticalresponse.visible = true end if dim dt data.datatable = gpcuser.getaccount(c.accountno) if dt isnot nothing if dt.rows.count > 0 dim dr data.datarow = dt.rows(0) if dr("creditstatus") > "0" , dr("stopcredit") = "n" , dr("credlimit") > "0" lstpaymentoptions.items.remove("please select") lstpaymentoptions.items.insert(0, new listitem("my global pc account", "99")) lstpaymentoptions.items.insert(0, "please select") end if end if end if dt.dispose() end if end if end sub 'radiobuttons set whether customer wants split shipping protected sub radlistsplit_selectedindexchanged(sender object, e system.eventargs) handles radlistsplit.selectedindexchanged if radlistsplit.selectedindex = "0" c.instructions = "**customer has selected split shipping**" elseif radlistsplit.selectedindex = "1" c.instructions = "" end if end sub protected sub btncontinue_click(byval sender object, byval e system.eventargs) handles btncontinue.click if typeof session("customer") gpcuser c = ctype(session("customer"), gpcuser) else exit sub end if if chksubscribe.checked = true dim listid integer = 284662333 dim ismember boolean = false dim newsession new loginargs() newsession.username = "austin@globalpc.co.nz" ' verticalresponse username newsession.password = "global2012" 'your verticalresponse password ' objla.impersonate_user = "subaccount@emailaddress.com"; // if accessing or acting subaccount, uncomment , replace applicable email address. newsession.session_duration_minutes = "120" dim [date] datetime = datetime.now ' generated creating service reference points verticalresponse wsdl. dim vruser new vrapi() ' let's try log in. login call return session id, use in subsequent calls. dim sessionid string = nothing try sessionid = vruser.login(newsession) catch ex system.exception txtadditionalinfo.text = ex.tostring() exit sub end try dim getmember new getlistmemberbyemailaddressargs() getmember.session_id = sessionid getmember.list_id = listid getmember.email_address = txtemail.text try vruser.getlistmemberbyemailaddress(getmember) ismember = true catch ex system.exception ismember = false end try if (ismember = false) dim nmember new listmember() nmember.list_id = listid dim memberdata nvpair() = new nvpair(2) {} memberdata(0) = new nvpair() memberdata(0).name = "email_address" memberdata(0).value = txtemail.text memberdata(1) = new nvpair() memberdata(1).name = "first_name" memberdata(1).value = txtfirstname.text memberdata(2) = new nvpair() memberdata(2).name = "last_name" memberdata(2).value = txtlastname.text nmember.member_data = memberdata dim objal new addlistmemberargs() objal.list_member = nmember objal.session_id = sessionid try vruser.addlistmember(objal) catch ex system.exception txtadditionalinfo.text = ex.tostring() exit sub end try else end if end if c.paymenttype = lstpaymentoptions.selectedvalue c.customerorderno = txtordernumber.text c.instructions += txtadditionalinfo.text c.createcustomerdetails(txtaccountname.text, txtfirstname.text, txtlastname.text, txtemail.text, txtaddress.text, txtsuburb.text, txtcitytown.text, txtpostcode.text, txtphone.text, txtmobile.text, lstcountry.selectedvalue) c.addshippingdetails(txtshippingfullname.text, txtshippingaddress.text, txtshippingcitytown.text, txtshippingsuburb.text, txtshippingpostcode.text, lstshippingcountry.selectedvalue) if c.customerid = 0 dim strpassword string = "" if c.generatedpassword <= "" strpassword = ucase(randompassword.generate(8, 8)) c.generatedpassword = strpassword else strpassword = c.generatedpassword end if gpcuser.addupdatecustomer(c) dim dt datatable = gpcuser.getuser(c.email, strpassword) if not dt nothing if dt.rows.count > 0 c.updateuser(dt.rows(0)("custid")) dim obj object = session("customer") session("customer") = c else end if else end if session("customer") = c end if sendupdateaccountemailmessage(c.emailcount) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' response.redirect("payment-details.aspx") end sub 'email validation <system.web.services.webmethod()> _ public shared function validateemail(email string) string dim wbclient webclient = new webclient() dim strurl string = configurationmanager.appsettings("websiteurlfull") + "/ajax/check_email_address.aspx?email=" + email dim reqhtml byte() reqhtml = wbclient.downloaddata(strurl) dim objutf8 utf8encoding = new utf8encoding() dim output string = objutf8.getstring(reqhtml) if string.isnullorempty(output) return string.empty dim c gpcuser if typeof httpcontext.current.session("customer") gpcuser c = ctype(httpcontext.current.session("customer"), gpcuser) exists = false if c.accountno > 0 exists = true end if return "" end if return output end function 'method send email globalpc private sub sendmessage(fromemail string, fromemailname string, _ toemails string(), isbodyhtml boolean, message string, subject string) dim mail mailmessage = new mailmessage mail.from = new mailaddress(fromemail, fromemailname) each toemail string in toemails mail.to.add(new mailaddress(toemail)) next mail.bcc.add(fromemail) mail.isbodyhtml = isbodyhtml mail.subject = subject mail.body = message dim s new smtpclient(system.configuration.configurationmanager.appsettings("mailserver")) s.send(mail) end sub 'sends email globalpc if customer updates account details. private sub sendupdateaccountemailmessage(emailcount integer) dim subject string = "alert : website user has updated details" dim message string message &= "account number " & c.accountno & " email address " & c.email & " has updated account. via page billing-details" & vbcrlf & vbcrlf message += "account name : " & txtaccountname.text & vbcrlf message += "first name : " & txtfirstname.text & vbcrlf message += "last name : " & txtlastname.text & vbcrlf message += "email : " & txtemail.text & vbcrlf message += "address : " & txtaddress.text & vbcrlf message += "suburb : " & txtsuburb.text & vbcrlf message += "city town : " & txtcitytown.text & vbcrlf message += "country : " & lstcountry.selectedvalue & vbcrlf message += "postcode : " & txtpostcode.text & vbcrlf message += "phone : " & txtphone.text & vbcrlf message += "mobile : " & txtmobile.text & vbcrlf message += vbcrlf & vbcrlf message += "shipping information" & vbcrlf message += "txtshippingfullname.text : " & txtshippingfullname.text & vbcrlf message += "txtshippingaddress.text : " & txtshippingaddress.text & vbcrlf message += "txtshippingcitytown.text : " & txtshippingcitytown.text & vbcrlf message += "txtshippingsuburb.text : " & txtshippingsuburb.text & vbcrlf message += "txtshippingpostcode.text : " & txtshippingpostcode.text & vbcrlf message += "lstshippingcountry.selectedvalue : " & lstshippingcountry.selectedvalue & vbcrlf message += vbcrlf & vbcrlf message += "more information" & vbcrlf message += "order no: " & c.customerorderno & vbcrlf message += "payment type: " & c.paymenttype & vbcrlf message += "instructions: " & c.instructions & vbcrlf message += vbcrlf & vbcrlf message += "regards" & vbcrlf & vbcrlf & "globalpc admin team" sendmessage(configurationmanager.appsettings("accountdetailsupdateemail"), "global pc", _ new string() {configurationmanager.appsettings("accountdetailsupdateemail")}, false, message, subject) end sub protected sub txtemail_textchanged(sender object, e system.eventargs) handles txtemail.textchanged dim listid integer = 284662333 dim ismember boolean = false dim newsession new loginargs() newsession.username = "austin@globalpc.co.nz" ' verticalresponse username newsession.password = "global2012" 'your verticalresponse password ' objla.impersonate_user = "subaccount@emailaddress.com"; // if accessing or acting subaccount, uncomment , replace applicable email address. newsession.session_duration_minutes = "120" dim [date] datetime = datetime.now ' generated creating service reference points verticalresponse wsdl. dim vruser new vrapi() ' let's try log in. login call return session id, use in subsequent calls. dim sessionid string = nothing try sessionid = vruser.login(newsession) catch ex system.exception 'lblmessage.text = ex.tostring() end try dim getmember new getlistmemberbyemailaddressargs() getmember.session_id = sessionid getmember.list_id = listid getmember.email_address = txtemail.text try vruser.getlistmemberbyemailaddress(getmember) ismember = true pnlverticalresponse.visible = false catch ex system.exception ismember = false pnlverticalresponse.visible = true end try end sub protected sub chksubscribe_checkedchanged(sender object, e system.eventargs) handles chksubscribe.checkedchanged if chksubscribe.checked = true bemember = true else bemember = false end if end sub end class
looks email checked against current addresses here
'email validation <system.web.services.webmethod()> _ public shared function validateemail(email string) string dim wbclient webclient = new webclient() dim strurl string = configurationmanager.appsettings("websiteurlfull") + "/ajax/check_email_address.aspx?email=" + email dim reqhtml byte() reqhtml = wbclient.downloaddata(strurl) dim objutf8 utf8encoding = new utf8encoding() dim output string = objutf8.getstring(reqhtml) if string.isnullorempty(output) return string.empty dim c gpcuser if typeof httpcontext.current.session("customer") gpcuser c = ctype(httpcontext.current.session("customer"), gpcuser) exists = false if c.accountno > 0 exists = true end if return "" end if
so exists variable tells if address matched.
try adding page_load method
if page.ispostback if exists btncontinue.enabled = false end if end if
as page posted server after button click, check see if exists true , if disable button.
p.s. change username/password use configurationmanger.appsettings , put username in web.config.
Comments
Post a Comment