JavaScript - Javascript Newsletter And Email Verify Query
long story short, I do work for a church, a charity asked me to fix some errors at their web site...1 problem arose and JavaScript is not my strong suite..they have an newsletter request form, just enter your email and your on their newsletter list, as you can see from the code below there is a problem, no valid email verify routine, if you just enter a space in the form, it will accept the info and send a blank request to the charity where an email addie should be... no clue how to fix, as I said javascript is not something I do at all....any help appreciated.
kenrich ======================= <script type="text/javascript"> $(function(){ $("#rform").submit(function(){return false;}); $("#rsubmit").click(function(){ if($("input#s").val() != "" && $("input#s").val() != 'Enter Email Address'){ $.get("/rsignup.php?email="+$("input#s").val(), function(data){ $("#rdiv").html(data).css("margin-top","15px"); }); } else { alert('Please enter your email address to subscribe'); } }); }); </script> <!-- BEGIN Form --> <div style="text-align: left;margin: 20px 0 -10px 10px;font-weight:bold;">Email Newsletter:</div> <div id="newsletterdiv" style="height:25px;"> <form name="optin" action="#" onsubmit="return false;" method="post" style="margin-bottom:2;" id="newsletterform"> <input type="hidden" name="vff" value="103"> <input type="hidden" name="vpp" value="i"> <div> <input value="Enter Email Address" onfocus="if (this.value == 'Enter Email Address') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter Email Address';}" name="ea" id="s" type="text"> <input id="newslettersubmit" value=" " type="submit" name="go"> </div> </form> </div> <!-- END Form --> Similar TutorialsHello I have a form validation script which checks for empty fields and an email address. The empty fields part seems to work, but not the validation (as long as I type characters in the email field, it seems to be acceptable). Here is what I have: Code: //function to check for empty fields function isEmpty(strfield1, strfield2, strfield3) { //change "name, email and subject" to your field names strfield1 = document.forms[0].ContactUs_Name.value strfield2 = document.forms[0].ContactUs_Email.value strfield3 = document.forms[0].ContactUs_Subject.value //name field if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ') { alert("\"Name\" is a mandatory field.\nPlease amend and retry.") return false; } //url field if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ') { alert("\"Email\" is a mandatory field.\nPlease amend and retry.") return false; } //title field if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ') { alert("\"Subject\" is a mandatory field.\nPlease amend and retry.") return false; } return true; } //function to check valid email address function isValidEmail(strEmail){ validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; strEmail = document.forms[0].email.value; // search email text for regular exp matches if (strEmail.search(validRegExp) == -1) { alert('A valid e-mail address is required.\nPlease amend and retry'); return false; } return true; } //function that performs all functions, defined in the onsubmit event handler function check(form){ if (isEmpty(form.ContactUs_Name)){ if (isEmpty(form.ContactUs_Email)){ if (isEmpty(form.ContactUs_Subject)){ if (isValidEmail(form.email)){ return true; } } } } return false; } </script> </head> <body bgcolor="#ECECEC" text="#000000"> <h3>Form validation with JavaScript</h3> <form name="theform" method="post" action="#" onSubmit="return check(this);"> Name:<br /> <input name="ContactUs_Name" type="text" /><br /> E-Mail:<br> <input name="ContactUs_Email" type="text" id="ContactUs_Email" /> <br /> Subject:<br> <input name="ContactUs_Subject" type="text" id="ContactUs_Subject" /> <br> I just wondered, is it here that the problem lies: if (isValidEmail(form.email)){ Thanks. Steve Hi, Is it possible in Javascript to verify a range of IP's for open port 80 and show as a hiperlink? The ideia is similar to ip scanners but it's for a web spider... Thanks Reply With Quote 01-11-2015, 01:04 PM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts Not possible IMO. Javascript cannot access or interact with the operating system. All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit. Hello to everyone! This is my first project in javascript and i need some help. I am using an 8*8 chess board with 8 queens placed by the user .Verify that they do not attack each other ,basically this means that there aren't two queens on the same line/column and diagonal and display a message box with the info. thanks guys! Shouldn't this work? It's letting the form submit to the next page when I add in this if statement: Code: var first = document.forms["contact1"].elements["name"].value; else if (!preg_match("/^[a-z]$/i", first)) { alert("Please enter only letters for your first name"); return false; } I'm trying to verify todays date against my input date, using a check value function, but for some reason when it comes to a day over 9 like 12/10/2009 or 12/20/2009 looks like is only recognizing the first number 12/1/2009 and 12/2/2009 and getting my alert back as to choose a future date, this is my code, any help would be greatly appreciated: var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() function checkValues() { if (owt8.dayr.value <=month+'/'+day+'/'+year ) { alert("Please enter a future date!"); return false; } owt8.submit(); alert("Your request has been submited") window.close() } Hello, I have a page with a lot of data but none of it is in a form; it is in a table. I would like a button that when pressed sends an HTML email to a hardcoded address without the page refreshing or being directed anywhere else. I can get the data I need from the table into a Javascript Array but Im not sure if what I want to do is achievable. Thanks This is an example of an email: REGION: CICSPSC1 PROGRAM: SCC23COB ABEND CODE: ASRA TRANSACTION: CORM DATE: 02/25/2010 TIME: 08:20:06 This javascript code is capable of parsing this email and return the information in the TRANSACTION: Code: var strReplace = email.body_text; strReplace = strReplace.replace(/\n/g,""); strReplace = strReplace.replace(/^REGION:\s+\w+\d+PROGRAM:\s+\w+\d+\w+/i,""); strReplace = strReplace.replace(/^\s+CODE:\s+\w+TRANSACTION:\s+/i,""); strReplace = strReplace.replace(/DATE.*$/i,""); gs.log(strReplace); So at the moment I am trying to parse this email information (below) and return the HOST: field data. Any help on this would be greatly appreciated!! Notification Type: PROBLEM Host: ka-whsym-r8 State: DOWN Address: 10.2.1.194 Info: PING CRITICAL - Packet loss = 100% Date/Time: Mon May 24 14:30:16 CDT 2010 This are my codes.. var add = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var email = form.txtEmail.value; if (add.test(email) = false) { alert("Please enter a valid email."); return false; } return true; } bt it wun work.. pls help.. I'm very new to javascript & would really appreciate any tips or help you guys could give me. Bascially, I have a form which I need to check if certain inputs are empty and send an alert... I also want to be able to send a client-side alert if the formatting of the email is wrong (it's not a valid email). I really don't want to use a jquery plugin or overcomplicate the code. At the moment I'm using the following code (which checks inputs are there) & was hoping someone could explain how I could add the email validation into this: Code: function checkform ( form ) { if (form.name.value == "") { alert( "Please add your name." ); form.name.focus(); return false ; } if (form.email.value == "") { alert( "Please enter your email address." ); form.email.focus(); return false ; } return true ; } Thanks in advance guys & i look forward to contributing on here in future . Also, if anyone has some good places for me to learn javascript, that too would be awesome! Can someone provide a code sample which uses RegExp in JavaScript to validate an email type of input in an HTML form?
Hi, I've been inherited a website from another web developer and I need to fix his code. In one part of the admin system, the user selects a template for the newsletter to use, types the subject and body text into a form, then submits it using a submit button. There is no problem with this code and the user is able to send newsletters out using the standard template (there is only one template). However, they require a preview button to check it looks how they want it to on the template. to get to the preview page (preview_mailing.php?template=1), there is a Javascript preview button, which uses the following code: Code: <script> function get_radio_value() { for (var i=0; i < document.add_form.template.length; i++) { if (document.add_form.template[i].checked) { return rad_val = document.add_form.template[i].value; } } } </script> <a href="javascript:;" title="Preview" target="_self" class="button" onclick="MM_openBrWindow('preview_mailing.php?template=' + get_radio_value(),'preview','scrollbars=yes,width=600,height=800');return false">Preview</a> <br/> When you click on this button, however, it does absolutely nothing and shows javascript:; as the link, but I'm sure this is what it is meant to show as the link? Hello I'm trying to create a graph that will accept 1 or multiple data sets depending on what the user selects. How can I add get the data into the graph using a loop? I want it to add a line for each selection. Thanks // Graph Data ############################################## var graphData = [{ // Visits data : <?php echo '['.implode($data).'],'?> color: '#71c73e' }, { // Visits data : <?php echo '['.implode($data_1).'],'?> color: '#red' }, ]; Hi There, I'm working on an application that potentially gets 1000s of geolocation queries per day and if I don this (as I've done it till now) in php, it works fine but I quickly run into OVER_QUERY_LIMIT error from the google map apis. Thus I think I'd better do it in javascript and just send the coordinates to the server for caching rather than querying from the server's IP. Now the url that sends back the location information looks like this: http://www.google.com/url?sa=D&q=htt...s3czv6-nMr_nbw and I was wondering how I can send a request to this url and parse the xml string that's returned with JavaScript to pass it on to a php (probably by get variables). Is there a handy method that's compatible accross a bunch of browsers incl. mobile ones? Thanks very much for some input! Ron Hi I am trying to get javascript to update a database for me. The reason is I need to use JS and not ASP is because I need to update whenever a user clicks on a button and from what I am told ASP can not do this. I tried following an example, and this is what I came up with. However I get the errors Error: Object expected and Excptected Hexadecimal Digit. Here is the code Code: <script language=javascript> function update() { var adoConn = new ActiveXObject("ADODB.Connection"); var adoRS = new ActiveXObject("ADODB.Recordset"); adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\data\user.mdb'"); adoRS.Open("Select * From ptotbl Where ID = 454"); adoRS.Edit; adoRS.Fields("Delete").value = "True"; adoRS.Update; adoRS.Close(); adoConn.Close(); } Thanks Hi I am trying to create a query string similar to the one available he http://andrewu.co.uk/tools/request/e.../example1.html The problem that I am having is that I have more than one button on my page and even though my id's are unique all of my data is displaying on the action page at the same time. The code that i am using for my buttons is: Code: <label for="name_1">Name:</label> <input type="text" name="name1" id="name_1" tabindex="1" size="40" value="Donald Duck" /> <br /> <br /> <input type="submit" id='view1' value="Submit" tabindex="2" /> <label for="name_1">Name:</label> <input type="text" name="name2" id="name_2" tabindex="1" size="40" value="Mickey Mouse" /> <br /> <br /> <input type="submit" id='view2' value="View" tabindex="2" /> I have a lot more than 2 buttons on my page. when a button is clicked I would like to be able to get the values from the query string and only see the values for the button that was clicked like this one: http://andrewu.co.uk/tools/request/e...ndrew+Urquhart but instead I am getting Name: Donald Duck, Name: Mickey Mouse. What would I have to add or change to obtain just one Name to display at a time but have it be different depending on which button is pressed? Hi there, I would like to validate the email address typed into the prompt message by the user, but to no avail. Can some kind soul help? Code: function addOption() { var new = prompt("Enter New Item:"); if (!new == "") { var answer = confirm ("Are you sure you want to add? ") if (answer)//if answer is true { var lst = document.getElementById('lstBx'); // listbox control id // Now we need to create a new 'option' tag to add to MyListbox for (var i = 0; i < lst.options.length; i++) { arrTexts = lst.options[i].text; if (arrTexts.toLowerCase() == newItem.toLowerCase()) { alert ("That email address is already included in the list - please enter another one."); break; } else { validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i; strEmail = lst.value; // search email text for regular exp matches if (strEmail.search(validRegExp) == -1) { alert('A valid e-mail address is required.\nPlease retry.'); return false; } var optionNew = document.createElement("option"); optionNew.value = new; // The value that this option will have optionNew.innerHTML = new; // The displayed text inside of the <option> tags // Finally, add the new option to the listbox lst.appendChild(optionNew); //sort items in listbox in alpha order arrTexts = new Array(); for(i=0; i<lst.length; i++) { arrTexts[i] = lst.options[i].text; } arrTexts.sort(); for(i=0; i<lst.length; i++) { lst.options[i].text = arrTexts[i]; lst.options[i].value = arrTexts[i]; } } return false; } } } else { if(new == "") { alert("Key something to textbox please."); } else alert("Cancelled."); } } Code: <select id="lstBx" name="listBox" size="6" style="width: 580px;"> <option>a@hotmail.com</option> <option>b@hotmail.com</option> <option>c@yahoo.com</option> <option>d@gmail.com</option> <option>e@ymail.com</option> <option>f@msn.com</option> </select> I have noooo idea if I am even posting this in the correct area, let alone the correct site. If not I apologize and maybe someone could direct me elsewhere. I am trying to add a custom search into my site. http://www.jeffknowsloans.com you can see it about the middle of the page. I am using the following script to do so. Code: <script type="text/javascript"> function dosearch() { var sf=document.searchform; var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value); window.location.href = submitto; return false; } </script> <form name="searchform" onSubmit="return dosearch();"> Select County <select name="sengines"> <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?housenum=&street=" selected>Washington</option> <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=&pg=1" selected>Ramsey</option> <option value="http://www.altavista.com/web/results?q=">Alta Vista</option> <option value="http://www.dogpile.com/info.dogpl/search/web/">Dogpile</option> </select> Street Address: <input type="text" name="searchterms"> <input type="submit" name="SearchSubmit" value="Search"> </form> here is the problem i am running into. I dont know how to ignore or add certain parts of the search when it sends. for example. take a look at Code: <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=&pg=1" selected>Ramsey</option> When i try to do a search under this drop down selection it doesnt work. because it needs the &pg=1 to be added to the users search request. Meaning if I set it to Code: http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street= they type in their street name and the street name inputs into the search query but it wont fully work because it doesnt add the &pg=1 after it all. how in the world do I get it to add things like that? ie how do i tell it to add certain strings that the outside source requires? like blank=&blank= or how do i get it to ignore certain &blank= commands. another example taking a look at Code: <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?housenum=&street=" selected>Washington</option> this search function should technically be Code: <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?" selected>Washington</option> however since i dont know how to add certain functions to the search i have to skip the housenum option. that means my customers cant search by street number. I want them to be able to type in their house number and their street address and it will change to what each seperate (outside) search engine needs. Does this make any sense at all? I have an array from a sql query that I need to use as variables in a javascript function. I have created the array, used JSON_ENCODE to bring the information into javascript, and so far everything works correctly. I am trying to use a list menu in html to select one on the indexes of the array so I can pass the information from the index to a javascript function. Here is the javascript function: Code: function selectTable(item_id) { var media = eval(<? echo json_encode($paperTable); ?>); var click_k_1=media[item_id]["click_k_1"]; var click_k_501=media[item_id]["click_k_501"]; var click_c_1=media[item_id]["click_c_1"]; var click_c_51=media[item_id["click_c_51"]; var click_c_101=media[item_id]["click_c_101"]; } Here is the list menu coding: Code: <select name="pprSel" size="1" id="pprSel" onChange="selectTable(this.value);" > <option value="204226">20# Bond</option> <option value="204788">70# White</option> <option value="204823">80# White</option> </select> Here is the source file results from the browser: Quote: function selectTable(item_id) { var media = eval({"1":{"item_id":"204226","item_description":"20# Bond","click_k_1":"0.1100","click_k_501":"0.0730","click_c_1":null,"click_c_51":null,"click_c_101":n ull},"2":{"item_id":"204788","item_description":"70# White","click_k_1":"0.1149","click_k_501":"0.0779","click_c_1":"0.8789","click_c_51":"0.5539","click _c_101":"0.3589"},"3":{"item_id":"204823","item_description":"80# White","click_k_1":"0.1591","click_k_501":"0.1221","click_c_1":"0.9231","click_c_51":"0.5981","click _c_101":"0.4031"}}); } I have tried a couple of different ways to pass one of the variables to a text field on the html form as an error check, with no success: Code: document.quote.data.value=media[item_id]["click_k_1"]; document.quote.data.value=click_k_1; The text field on the html form is id='data', the form is id='quote'. the only thing I can think of for the reason I am not getting anything in my text field is that my variable is not getting set up properly. Can anyone help? TIA |