JavaScript - Transfer Data From A Form
Hi,
I have a rather complicated problem for me as it involves both php and js. And I'm getting lost... Let me explain: On a page, order.html, I have a form including the following fields: - name - comment When posted, it is linked to request.php and request.validation.js, to end up on confirmation.php. On confirmation.php, I would like to reuse the information entered in the fields on order.php (name, email, comment) to display them on the page. My issue I can't find how to 'take them along' in request.php / request.validation.js to confirmation.php where I'm trying to display them with : Code: Contact: <span id="name"><?php echo($_POST['name']); ?></span> etc. For reference, here are my files request.php and request.validation.js: PHP Code: <?php // CONFIGURATION -------------------------------------------------------------- // This is the email where the contact mails will be sent to. $config['recipient'] = 'mail@mail.com'; // This is the subject line for contact emails. // The variable %name% will be replaced with the reference ordered. $config['subject'] = 'Website enquiry from %name%'; // These are the messages displayed in case of form errors. $config['errors'] = array ( 'no_name' => 'Veuillez entrer votre nom.', 'no_email' => 'Votre adresse email est requise.', 'invalid_email' => 'Votre adresse email n est pas valide.', ); // END OF CONFIGURATION ------------------------------------------------------- // Ignore non-POST requests if ( ! $_POST) exit('Nothing to see here. Please go back to the site.'); // Was this an AJAX request or not? $ajax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); // Set the correct HTTP headers header('Content-Type: text/'.($ajax ? 'plain' : 'html').'; charset=utf-8'); // Extract and trim contactform values $name = isset($_POST['name']) ? trim($_POST['name']) : ''; $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; // Take care of magic quotes if needed (you really should have them disabled) set_magic_quotes_runtime(0); if (get_magic_quotes_gpc()) { $name = stripslashes($name); $email = stripslashes($email); $comment = stripslashes($comment); } // Initialize the errors array which will also be sent back as a JSON object $errors = NULL; // Validate name if ($name == '' || strpos($name, "\r") || strpos($name, "\n")) { $errors['name'] = $config['errors']['no_name']; } // Validate email if ($email == '') { $errors['email'] = $config['errors']['no_email']; } elseif ( ! preg_match('/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD', $email)) { $errors['email'] = $config['errors']['invalid_email']; } // Validation succeeded if (empty($errors)) { // Prepare subject line $subject = str_replace('%name%', $name, $config['subject']); // Set date $todayis = date("l, F j, Y") ; // Prepare message $message = "Date: $todayis Nom: $name email: $email Commentai $comment"; // Additional mail headers $headers = 'Content-Type: text/plain; charset=utf-8'."\r\n"; $headers .= 'From: '.$email; // Send the mail if ( ! mail($config['recipient'], $subject, $message, $headers)) { $errors['server'] = 'Server problem'; } } if ($ajax) { // Output the possible errors as a JSON object echo json_encode($errors); } else { // Show a simple HTML feedback message in case of non-javascript support if (empty($errors)) { header('Location: ../steps/confirmation.php'); } else { echo '<h2>Oups!</h2>'; echo '<ul><li>'; echo implode('</li><li>', $errors); echo '</li></ul>'; echo '<br><br><a href="javascript:history.back(-1);">Retour</a>'; } } Code: /* * Request Form Validation v1.0 * By Simon Bouchard <www.simonbouchard.com> * You need at least PHP v5.2.x with JSON support for the live validation to work. */ jQuery(document).ready(function(){ jQuery('#requestform').submit(function() { // Disable the submit button jQuery('#requestform input[type=submit]') .attr('value', 'Send...') .attr('disabled', 'disabled'); // AJAX POST request jQuery.post( jQuery(this).attr('action'), { name:jQuery('#name').val(), email:jQuery('#email').val(), comment:jQuery('#comment').val(), }, function(errors) { // No errors if (errors == null) { document.location.href="confirmation.php"; } // Errors else { // Re-enable the submit button jQuery('#requestform input[type=submit]') .removeAttr('disabled') .attr('value', 'Envoyer'); // Technical server problem, the email could not be sent if (errors.server != null) { alert(errors.server); return false; } // Empty the errorbox and reset the error alerts jQuery('#requestform .errorbox').html('<ul></ul>').show(); jQuery('#requestform li').removeClass('alert'); // Loop over the errors, mark the corresponding input fields, // and add the error messages to the errorbox. for (field in errors) { if (errors[field] != null) { jQuery('#' + field).parent('li').addClass('alert'); jQuery('#requestform .errorbox ul').append('<li>' + errors[field] + '</li>'); } } } }, 'json' ); // Prevent non-AJAX form submission return false; }); }); Thanks for your help. M. Similar TutorialsBasically I have comments posted on articles and I want to allow users to report them if they find inappropriate content. I want them to be able to click on icon on the comment which will open up a pop-up. Then in the pop-up they can type why they are reporting the comment. Code: <script type="text/javascript"> function popup() { Report = window.open('/report.php','Report','width=350, height=400'); document.reportform.submit(); } </script> <form action="/report.php" name="reportform" method="post" target="Report"> <input type="hidden" name="reporter_id" value = "<?php echo $user_id; ?>" /> <input type="hidden" name="reported_id" value="<?php echo $row['uid'] ?>" /> <input type="hidden" name="comment_id" value="<?php echo $row['id'] ?>" /> <a href="#" name="reportform" class="submit" onclick="return popup();"> Report</a></form> I've been messing with this code for a while now. This code successfully brings up the pop-up, but it doesn't transfer the form data. My main coding language is PHP, and I'm in the process of learning Javascript. Can anyone help? I am currently creating which will allow the user to upload their own pictures. For this I am opening a new pop up window where the user can select the file they wish and then upload it (similar to ebay's picture upload). The pop up works fine and so does the file upload however I am having trouble transferring any data from the pop up window back to the parent window. I have been investigating the opener method but cannot seem to get it to work. Below is some simple code that I've been trying to get to work... Thanks for any help! first page... Code: <form name="loadpic" id="loadpic" action="createPost.php" method="post"> <br /> <br /> Testing transfer between pages... <input type="button" value="open pop up" onclick="window.open('popup.php','pop up box','width=400,height=200')" /> <br /> <br /> <span name="myspan" id="myspan">text here</span> </form> pop up page... Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Pop Up</title> <script language=javascript> function transfer(){ opener.document.loadpic.myspan.innerHTML = "working"; window.close(); } </script> </head> <body> This is the pop-up page! <input type="button" onclick="return transfer()" value="press me" /> </body> Hi guys, Been stuck for a few days with this scenario. Any help? The alert box appears on an error. But the submitting won't stop. The details are submitted and the form is processed. Any help is greatly appreciated... Code: <html> <head> <script type="text/javascript" src="email_helper/jscripts/tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "textareas", theme : "simple" }); </script> <script language="javascript"> function MM_openBrWindow(theURL,winName,features) { window.open(theURL,winName,features); } function err_check(){ var email = document.getElementById('to_email').value; if(email.length==0){ alert('Please Enter Email Address'); return false; } var AtPos = email.indexOf("@") var StopPos = email.lastIndexOf(".") if (AtPos == -1 || StopPos == -1) { alert("Please Enter Valid Email Address"); document.getElementById('email').focus(); return false; } email = document.getElementById('cc_email').value; if(email.length != 0){ var AtPos = email.indexOf("@") var StopPos = email.lastIndexOf(".") if (AtPos == -1 || StopPos == -1) { alert("Please Enter Valid Email Address"); document.getElementById('email').focus(); return false; } } var answer = confirm ("Send E-Mail?"); if (!answer){ return false; } } </script> <!-- /TinyMCE --> <style type="text/css"> body, table, td, th{ background-color:#CCCCCC; font-family: Arial; font-size:14px; } .que{ font-weight:bold; } </style> </head> <body> <form method="post" enctype="multipart/form-data"> <?php include 'library/database.php'; include 'library/opendb.php'; $query = mysql_query("SELECT email,contact,mobile FROM users WHERE user_id='$uid'") or die(mysql_error()); $row = mysql_fetch_row($query); $from_email = $row[0]; $from_person = $row[1]; $from_mobile = $row[2]; $query = mysql_query("SELECT customer_id FROM campaign_summary WHERE camp_id='$camp_id'") or die(mysql_error()); $row = mysql_fetch_row($query); $cusid = $row[0]; $query = mysql_query("SELECT email FROM client_info WHERE comp_id='$cusid'") or die(mysql_error()); $row = mysql_fetch_row($query); $toer = $row[0]; include 'library/closedb.php'; ?> <table width="100%" border="0"> <tr><td rowspan="4"><input type="submit" name="send_email" id="send_email" style="height:50px; width:100px;" value="SEND" onClick="return err_check();" /></td><td><span class="que">From : </span></td><td colspan="3"><?php echo $from_email; ?><input type="hidden" name="from_mail" id="from_mail" /><input type="hidden" name="camp_id" id="camp_id" value="<?php echo $camp_id;?>"/></td></tr> <tr><td><span class="que">To : </span></td><td colspan="3"><input name="to_email" id="to_email" style="width:250px;" value="<?php echo $toer;?>"/></td></tr> <tr><td><span class="que">CC : </span></td><td colspan="3"><input name="cc_email" id="cc_email" style="width:250px;"/></td></tr> <tr><td><span class="que">Subject : </span></td><td colspan="3"><input style="width:300px;" name="subject" id="subject" /></td></tr> <tr><td rowspan="1" colspan="2"> </td><td><input type="checkbox" name="ori_pdf" id="ori_pdf" checked /> PDF Quotation</td><td> </td><td> </td></tr><tr><td colspan="2"><span class="que">Credit Application</span></td><td><input type="checkbox" name="corporate" id="corporate"/>Corporate</td><td><input type="checkbox" name="individual" id="individual" />Individual</td><td><input type="checkbox" name="cash" id="cash" />Cash Account</td> </tr> <tr> <td colspan="2" rowspan="3"></td><td><input type="checkbox" name="tabloid" id="tabloid" />Tabloid Example</td> <td><input type="checkbox" name="broadsheet" id="broadsheet" />Broadsheet Example</td></tr> <tr><td><input type="checkbox" name="colmt" id="colmt" />Column Sizes Tabloid</td> <td><input type="checkbox" name="colmb" id="colmb" />Column Sizes Broadsheet</td></tr> <tr><td><input type="checkbox" name="maps" id="maps" />Maps / Distribution</td><td colspan="2" align="right">External Attachments <input id="upload_file" name="upload_file" type="file"/> </td></tr> <tr><td colspan="2"><span class="que">Message :</span></td><td colspan="3"> <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 100%"> <?php echo "<br><br><br>" . $from_person . "<br>" . $from_mobile; ?> </textarea> </td></tr> </table> </form> </body> </html> I've done some searching and can't find an exact answer, so I'll ask it here. I want to know if it is possible (by fairly simple means) to take the results from one page and transfer it to another? Here is the dilema. I've helped with an order form page for a local company. They have to change the items and options weekly, so they chose to have the customer enter in the total for their order. They now want to add a Paypal button for those that wish to pay by credit and ahead of time. But the order form has to be submitted prior to the customer seeing the PayPal button. We decided to put it on the confirmation page IF AND ONLY IF the total amount the customer manually added could be transferred to the confirmation page. Is this possible with some script?
Hi, How do I "select a 'read more' button on a page and obtain the balance of the article"? Novice...... Thank You I am trying to transfer the variables of the form (username & password )in the html page to the process.php page which are both given below. However I am not able to read those values from the process.php page. Can anyone please let me know what is going wrong here? Thanks in advance and appreciate your help. HTML Page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script language="JavaScript" type="text/javascript"> function xor_str() { var username_val = document.forms['the_form'].elements["username"].value; var password_val = document.forms['the_form'].elements["password"].value; var xor_key='1234'; var username_res=""; var password_res="" for(i=0;i<username_val.length;++i) { username_res+=String.fromCharCode(xor_key^username_val.charCodeAt(i)); } for(i=0;i<password_val.length;++i) { password_res+=String.fromCharCode(xor_key^password_val.charCodeAt(i)); } // XOR is done //shifting the username_res to the left by 1 bit //username_res = username_res << 1; //shifting the password_res to the left by 1 bit //password_res = password_res << 1; //setting the xor'ed and shifted value for submission document.forms['the_form'].elements["username"].value = username_res; document.forms['the_form'].elements["password"].value = password_res; //alert("UserName: " + username_res); //alert("Password: "+ password_res); the_form.submit(); // is this step right? } </script> </head> <body> <form name="the_form" action="process.php" method="post"> <table> <tr><td colspan="3">Username:<input type="text" name="username"></td></tr> <tr><td>Password: <input type="text" name="password"></td><td colspan="2"><input type="button" onClick="xor_str()" value="Submit"></td></tr> </table> </form> </body>s </html> Process.php page <html><body> <?php $username = $_POST['username']; $password = $_POST['password']; echo "You ordered ". $username . " " . $password . ".<br />"; echo "Thank you "; ?> </body></html> Hey friends, I'm not sure where to post this, so redirect me if there is a more appropriate location, please. I am having a very strange problem with a javascript gallery contained within a site I am working on. The problem is, that it broke (appears to be a non-working javascript) while transferring servers (from test server to client server). It makes me believe that it is a filepath problem, but I have checked over the filepaths, the javascript, the css, the html, substituted the new files back into the test server one by one, which, all work on the test server (and vice versa, the old files dont work on the new server)... and cannot seem to find the problem. I am using noobSlide gallery and have replaced the JS files incase they became corrupted in any way during the transfer. The website is located he http://www.design-evolve.com The gallery is located within Landscape-> Residential Landscape (under the Projects section). Once you reach the Residential Landscape, the Gallery is at the top of the page, and the arrows *should* scroll you through 5 images. Can anyone give me a fresh set of eyes to see if I am overlooking something? Any help would be much appreciated. Thanks, -Andrew I have this code to prompt for text input and then I want to run script.sh: Code: <script type="text/javascript"> function runscript() { var x=prompt("Enter text:"); //this is where I'm lost var xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","/cgi-bin/script.sh"); xmlhttp.send() } </script> Is it possible to substitute x above as the value for $txt in script.sh which looks like this below and how please? Code: #!/bin/bash echo "Content-type: text/html" echo "" <some xmlrpc command> "add text $txt" Hi Folks, I'm trying to figure out a script to transfer selected checkbox information to another page. I'm making a needs list for a non-profit group and the list is "huge" so I thought it would be nice to have something where the viewer could have a list of the items they checked to donate instead of printing out or transmitting the six pages for the entire list. I found a script in the archives from 10/2002 that "Adios" wrote in reply to an inquiry. It is real close to what I want but it involves transfering graphics instead of the text information from the checkbox. I've been working on it for several days but cannot get it to work. Here's Adios' script: <html> <head> <title>untitled</title> <script type="text/javascript" language="javascript"> var lefty = righty = null; function pop_twins() { lefty = open('lefty.htm','lefty','left=0,top=0,width='+screen.availWidth/2+',height='+screen.availHeight+',status=0'); righty = open('righty.htm','righty','left='+screen.availWidth/2+',top=0,width='+screen.availWidth/2+',height='+screen.availHeight+',status=0'); lefty.focus(); righty.focus(); } </script> </head> <body> <a href="javascript:void pop_twins()">pop 'em</a> </body> </html> [lefty.htm] <html> <head> <title>The Source</title> <base href="http://aabode.com/victoria/images/"> <script type="text/javascript" language="javascript"> var path = 'http://aabode.com/victoria/images/'; function addIMG() { var HTML = '', img, box_arr = document.addform.ImgAdd, which = 0; HTML += '<html><head><title>The Destination</title></head><body>'; HTML += '<h1>&#149; The Destination &#149;</h1>'; while (box = box_arr[which++]) if (box.checked) HTML += '<img vspace="5" border="1" src="' + path + box.value + '"><br>'; HTML += '</body></html>'; if (opener.righty) { opener.righty.document.write(HTML); opener.righty.document.close(); } } </script> </head> <body> <h1>&#149; The Source &#149;</h1> <form name="addform"> <input type="checkbox" name="ImgAdd" value="apple.jpg" onclick="addIMG()"> <img align="middle" vspace="5" border="1" src="apple.jpg"><br> <input type="checkbox" name="ImgAdd" value="strawberry.jpg" onclick="addIMG()"> <img align="middle" vspace="5" border="1" src="strawberry.jpg"><br> <input type="checkbox" name="ImgAdd" value="pumpkin.jpg" onclick="addIMG()"> <img align="middle" vspace="5" border="1" src="pumpkin.jpg"><br> <input type="checkbox" name="ImgAdd" value="lettuce.jpg" onclick="addIMG()"> <img align="middle" vspace="5" border="1" src="lettuce.jpg"><br> <input type="checkbox" name="ImgAdd" value="raspberries.jpg" onclick="addIMG()"> <img align="middle" vspace="5" border="1" src="raspberries.jpg"><br> <input type="checkbox" name="ImgAdd" value="tomatoes.jpg" onclick="addIMG()"> <img align="middle" vspace="5" border="1" src="tomatoes.jpg"> </form> </body> </html> [righty.htm] <html> <head> <title>The Destination</title> <body> <h1>&#149; The Destination &#149;</h1> </body> </html> I would like to also include a print function and submit. The print feature is not a big issue as the viewer can print from the browser but I thought it would make the transferred information page a bit more snazzy and they will have a record of thier selections. On the submit I don't have a URL setup yet but if you could put something like "URL HERE" in the script placement I can change it when they get up and going. Thanks in advance for your help, and thanks for taking the time to read all this. hello i am trying to fire a form which after the call to retrieve the data, populate the form with the data. i can see from firebug that the json data is being captured, but cannot seem to be able to populate the form with it. i am using a jquery plugin facybox, that opens the form, but the fields are blank. i have attached my code and would be grateful if someone could tell me where i am going wrong? many thanks js code Code: <script type="text/javascript"> function edit(com, grid) { if (com == 'Edit') { if($('.trSelected').length>0){ if($('.trSelected').length>1){ alert('Please select just one row'); return; } var items = $('.trSelected'); var itemlist =''; for(i=0;i<items.length;i++){ itemlist+= items[i].id.substr(3); } $.ajax({ type: "POST", dataType: "json", url: "tempcontact.php", data: "items="+itemlist, success: function(data){ document.getElementById('id').value = data.id; document.getElementById('email').value = data.email; $("#flex1").flexReload(); } }); /*and so on then you can call facybox*/ jQuery.facybox({ div: "#editform"}); } else{ alert('Please select a row to edit.'); } } } </script> form Code: <div id="editform" style="display:none;"> <form action="conedit.php" method="post" class="webform"> <fieldset> <legend><span>Update Contact</span></legend> <br /> <div id="dataText">Please delete the fields if there is no data 'No data to display'.</div> <label for="id">ID:</label> <input id="id" name="id" class="text" type="text" value="" /> <label for="name">Full Name:</label> <input id="name" name="name" class="text" type="text" value="" /> <label for="email">Email address:</label> <input id="email" name="email" class="text" type="text" value="" /> <label for="phone">Telephone:</label> <input id="phone" name="phone" class="text" type="text" value="" /> <label for="mobile">Mobile:</label> <input id="mobile" name="mobile" class="text" type="text" value="" /> <label for="fax">Fax:</label> <input id="fax" name="fax" class="text" type="text" value="" /> <label for="notes">Notes:</label> <textarea name="notes" cols="25" rows="3"></textarea> </fieldset> <input class="submit" type="submit" name="submit" value="Update" /> </form> </div> I am trying to get around using server side scripting for an issue on a webpage. I have a basic html form like this: Code: <html> <body> <FORM NAME="myform" ACTION="" METHOD="GET">Enter something in the box: <BR> <INPUT TYPE="text" NAME="inputbox" VALUE=""><P> <INPUT TYPE="button" NAME="button" Value="Click" onClick="testResult (this.form)"> </body> </html> I know I can use JavaScript to capture the data like this: Code: function testResults (form) { var TestVar = form.inputbox.value; alert ("You typed: " + TestVar); } Instead of alerting it, can I save the data in an iframe? Will it stay there once they leave the page? I want the iframe to eventually contain info from lots of people's answers. I am wanting to simulate saving the answers to a text file on the server. Hello, I used a standard orderform which I expanded. With this form people can order some products. But when I submit the form with data from a javascript the mail is empty. Can anyone help? I am just a beginner.... You can try the form here Thanks in advance! Hein. I have a long survey form and once its submitted it gets recorded into a database. I would love to be able to save a PDF version of the HTML form with all their radio buttons and textfields filled out at the same time its submitted. It would need a unique name that matches their record in the database (maybe it pulls the data that was entered into one of the form fields for the name). Whether it gets uploaded to an ftp or just emailed to a mailbox doesn't really matter. The purpose of this is to basically have a visual interpretation of the data by a single user. Is something like this even possible? I am working on my form. Once user put data in the form, I want to save it as cookie and display it in another page as form processor. In my html file therefore, I have Code: <form id="frmBuyer" method="get" action="FormProcessor_Cookies.html" enctype="application/x-www-form-urlencoded" onsubmit="return validate();" onreset="location.reload();"> which is basically validate all the data and once it meets the requirement, it goes to FormProcessor_Cookies.html. So, i put a function in my js file to get all the data as cookie as following. Code: function createCookie(){ document.cookie = first + "=" + encodeURIComponent(document.forms[0].FirstName.value); document.cookie = last + "=" + encodeURIComponent(document.forms[0].LastName.value); document.cookie = phone1 + "=" + encodeURIComponent(document.forms[0].PhoneA.value); document.cookie = phone2 + "=" + encodeURIComponent(document.forms[0].PhoneB.value); document.cookie = phone3 + "=" + encodeURIComponent(document.forms[0].PhoneC.value); document.cookie = email + "=" + encodeURIComponent(document.forms[0].Email.value); location.href = "cookie.html"; } and I called this function after it validates. Code: function validate(){ var blnError = false; var zip = document.getElementById("Zip").value; var textBoxthree = document.getElementById("third"); var textLengththree = textBoxthree.value.length; var textBoxtwo = document.getElementById("second"); var textLengthtwo = textBoxtwo.value.length; var textBoxone = document.getElementById("first"); var textLengthone = textBoxone.value.length; var patternZip = new RegExp("^([0-9]){5}(([ ]|[-])?([0-9]){4})?$"); if (document.forms[0].Zip.value == ""||!patternZip.test(document.forms[0].Zip.value)){ document.getElementById('E_Zip').style.display="inline"; document.forms[0].Zip.focus(); document.forms[0].Zip.style.backgroundColor="lemonchiffon" blnError = true; } else{ document.getElementById('E_Zip').style.display="none"; document.forms[0].Zip.style.backgroundColor="white" } var patternCity = new RegExp("^(?:[a-zA-Z]+(?:[.'\-,])?\s?)+$"); if (document.forms[0].City.value == ""||!patternCity.test(document.forms[0].City.value)){ document.getElementById('E_City').style.display="inline"; document.forms[0].City.focus(); document.forms[0].City.style.backgroundColor="lemonchiffon" blnError = true; } else{ document.getElementById('E_City').style.display="none"; document.forms[0].City.style.backgroundColor="white" } var patternAddress = new RegExp("^[a-zA-Z]+.*|.*[a-zA-Z]+|.*[a-zA-Z]+.*$"); if (document.forms[0].Address1.value == ""||!patternAddress.test(document.forms[0].Address1.value)){ document.getElementById('E_Address1').style.display="inline"; document.forms[0].Address1.focus(); document.forms[0].Address1.style.backgroundColor="lemonchiffon" blnError = true; } else{ document.getElementById('E_Address1').style.display="none"; document.forms[0].Address1.style.backgroundColor="white" } var patternConfirm = new RegExp("^[_a-zA-Z0-9\\-]+(\.[_a-zA-Z0-9\\-]+)*@[a-zA-Z0-9\\-]+(\.[a-aZ-Z0-9\\-]+)*(\.[a-z]{2,3})$"); if (document.forms[0].ConfirmEmail.value == "" ||!patternConfirm.test(document.forms[0].ConfirmEmail.value) ||document.forms[0].ConfirmEmail.value != document.forms[0].Email.value){ document.getElementById('E_ConfirmEmail').style.display="inline"; document.forms[0].ConfirmEmail.focus(); document.forms[0].ConfirmEmail.style.backgroundColor="lemonchiffon" blnError = true; } else{ document.getElementById('E_ConfirmEmail').style.display="none"; document.forms[0].ConfirmEmail.style.backgroundColor="white" } var patternEmail = new RegExp("^[_a-zA-Z0-9\\-]+(\.[_a-zA-Z0-9\\-]+)*@[a-zA-Z0-9\\-]+(\.[a-aZ-Z0-9\\-]+)*(\.[a-z]{2,3})$"); if (document.forms[0].Email.value == ""||!patternEmail.test(document.forms[0].Email.value)){ document.getElementById('E_Email').style.display="inline"; document.forms[0].Email.focus(); document.forms[0].Email.style.backgroundColor="lemonchiffon" blnError = true; } else{ document.getElementById('E_Email').style.display="none"; document.forms[0].Email.style.backgroundColor="white" } var patternPhoneA = new RegExp("^\\d{3}$"); var patternPhoneB = new RegExp("^\\d{3}$"); var patternPhoneC = new RegExp("^\\d{4}$"); if(patternPhoneC.test(document.forms[0].PhoneC.value) &&patternPhoneB.test(document.forms[0].PhoneB.value) &&patternPhoneA.test(document.forms[0].PhoneA.value)){ document.getElementById('E_Phone').style.display="none"; } if(patternPhoneC.test(document.forms[0].PhoneC.value)){ document.forms[0].PhoneC.style.backgroundColor="white"} if(patternPhoneB.test(document.forms[0].PhoneB.value)){ document.forms[0].PhoneB.style.backgroundColor="white"} if(patternPhoneA.test(document.forms[0].PhoneA.value)){ document.forms[0].PhoneA.style.backgroundColor="white"} if (!patternPhoneC.test(document.forms[0].PhoneC.value)){ document.getElementById('E_Phone').style.display="inline"; document.forms[0].PhoneC.focus(); document.forms[0].PhoneC.style.backgroundColor="lemonchiffon" } if (!patternPhoneB.test(document.forms[0].PhoneB.value)){ document.getElementById('E_Phone').style.display="inline"; document.forms[0].PhoneB.focus(); document.forms[0].PhoneB.style.backgroundColor="lemonchiffon" } if (!patternPhoneA.test(document.forms[0].PhoneA.value)){ document.getElementById('E_Phone').style.display="inline"; document.forms[0].PhoneA.focus(); document.forms[0].PhoneA.style.backgroundColor="lemonchiffon" } var patternLast = new RegExp("^[a-zA-Z]+.*|.*[a-zA-Z]+|.*[a-zA-Z]+.*$"); if (document.forms[0].LastName.value == ""||!patternLast.test(document.forms[0].LastName.value)){ document.getElementById('E_LastName').style.display="inline"; document.forms[0].LastName.style.backgroundColor="lemonchiffon" blnError = true; } else{ document.getElementById('E_LastName').style.display="none"; document.forms[0].LastName.style.backgroundColor="white" } var patternFirst = new RegExp("^[a-zA-Z]+.*|.*[a-zA-Z]+|.*[a-zA-Z]+.*$"); if (document.forms[0].FirstName.value == ""||!patternFirst.test(document.forms[0].FirstName.value)){ document.getElementById('E_FirstName').style.display="inline"; document.forms[0].FirstName.style.backgroundColor="lemonchiffon" blnError = true; } else{ document.getElementById('E_FirstName').style.display="none"; document.forms[0].FirstName.style.backgroundColor="white" } if (blnError == true){ document.getElementById('E_Alert').style.display="inline"; return false; } else { document.getElementById('E_Alert').style.display="none"; createCookie(); return true; } } Lastly, I tried to display all the cookies in my "FormProcessor_Cookies.html" page Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="author" content="" /> <meta name="description" content="Home" /> <meta name="keywords" content="Client Side Programming, JavaScript, CSS" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Language" content="en-us" /> <link rel="stylesheet" href="javascript.css"/> <script type="text/javascript" src="shopping.js"></script> <title>Homepage::Seunghun Jun</title> </head> <body> <div id="container"> <!-- Begin web page --> <div id="header"><!-- Header and Navigation --> <!-- Page Heading --><!-- Navigation --> <script type="text/javascript"> displayHeader(); </script> <br/><br/><br/><br/> </div> <div id="content"> <!-- Main Content --><div id="submited"> <script type="text/javascript"> /* <![CDATA[ */ document.write(documetn.cookie;); /* ]]> */ </script></div> </div><br/><br/><br/><br/> <div id="footer"> <!-- Footer --> <!-- Begin Footer Div--> <script type="text/javascript">displayFooter();</script> <!-- End Footer Div --> </div> <!--End web page --> </div> </body> </html> And its not showing any messages...I know I am asking to much...but could any expert can help me what is wrong and how I can fix this? I have 2 types of addresses 1. Permanent address > Postal code, Street, City, State, Country 2. Current address > Postal code, Street, City, State, Country and a check box 'Copy from Permanent address' with Current address when i checked that check box then all values from 'Permanent address' will be copy to 'Current address' Please send me the code Hi I own two websites, site1.com and site2.com site1.com is Java jsp site2.com is Apache php I don't know if this is possible I think no but at least let me clear what I am plaining to do. The site1.com has the following form and I want the data submitted to that form get stored in site2.com. The form in brief is as following : Code: <FORM METHOD=POST ACTION="SaveName.jsp"> What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR> What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR> What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4> <P><INPUT TYPE=SUBMIT> </FORM> Regards HTML: Code: <script src="./include/js/drinkValidation.js" type="text/javascript"></script> <form name="add-drinks" action="include/add-drink.php" method="POST" onSubmit="return addDrinkFormValidation(this);" enctype="multipart/form-data" > <span id="colour" class='modify_form'> <label for='drinkColour'>Spirit Colour:</label> <br /> <select name='drinkColour' tabindex=1> <option value='' >None</option> <option value='R' >R</option> <option value='G' >G</option> <option value='Y' >Y</option> </select> </span> <div class='modify_form'> <label for='drinkType'>Type:</label> <br /> <select name='drinkType' tabindex=1 onChange="HideObjects(this.value)"> <option value="">Select a Drink type:</option> <option value='Cask' >Cask Ales</option> <option value='Guest' >Guest Ale</option> <option value='Lager' >Lager</option> <option value='Bottled Beers' >Bottled Beer</option> <option value='Wines' >Wine</option> <option value='Ciders' >Cider</option> <option value='Softs' >Soft</option> <option value='Spirits' >Spirit</option> </select> </div> <div id="drinkABV" class='modify_form'> <label for='drinkABV'>ABV:</label> <br /> <input name='drinkABV' size='2' tabindex=4 maxlength="4" placeholder="ie: 4.2"/> <label for='drinkABV'>%</label> </div> <div id="name"class='modify_form'> <label for='name'>Name:</label> <br /> <input name='name' size='25' tabindex=3 placeholder="Drink name"/> </div> <div id="drinkInfo" class='modify_form'> <label for='drinkInfo'>Description:</label> <br /> <textarea name='drinkInfo' rows='5' cols='30' maxlength='255' tabindex=5 placeholder="Max 255 characters"></textarea> </div> <div id="pint" class='modify_form'> <label for='drinkPintPrice'>Pint (£):</label> <br /> <input name='drinkPintPrice' size='10' tabindex=8 /> </div> <div id="halfpint" class='modify_form'> <label for='drinkHalfPrice'>Half Pint (£):</label> <br /> <input name='drinkHalfPrice' size='10' tabindex=7 /> </div> <div id="drinkSpecialPrice" class='modify_form'> <label for='drinkSpecialPrice'>Offer Price (£):</label> <br /> <input name='drinkSpecialPrice' size='10'tabindex=6 /> </div> <div id="drinkbottlePrice" class='modify_form'> <label for='drinkbottlePrice'>Bottle/Spirit Price (£):</label> <br /> <input name='drinkbottlePrice' size='10'tabindex=6 /> </div> <br /> <br /> <input type="file" name="cons_image" /> <br /> <br /> <div id='submit'> <input type='submit' value='Add New Drink' /> </div> <br /> <p><b>Please add the information you wish to add then click Add New Drink</b></p> </form> Javascript containing validation Code: var ck_abv = /[0-9]{1,2}\\.[0-9]{1}$/; var ck_price = /[0-9]{1,2}\\.[0-9]{2}$/; var ck_name = /^[A-Za-z0-9 ]{3,20}$/; var ck_info = /^[A-Za-z0-9 ]{3,255}$/; alert ("Im in the file"); function addDrinkFormValidation(form){ var type = form.drinkType.value; var abv = form.drinkABV.value; var name = form.name.value; var info = form.drinkInfo.value; var pint = form.pint.value; var halfpint = form.halfpint.value; var bottle = form.drinkbottleprice.value; var offer = form.drinkSpecialprice.value; var errors = []; alert (form); alert (type); alert (abv); alert (info); alert (pint); alert (halfpint); alert ("Anything showing"); if(type==0){ errors[errors.length] = "Please select a drink type."; } if(!ck_name.test(name) || (name == "")){ errors[errors.length] = "Please enter a drink name."; } if(!ck_info.test(info) || (info == "")){ errors[errors.length] = "Please enter a drink description."; } if(!ck_abv.test(abv)){ errors[errors.length] = "Illegal character in ABV"; } if(!ck_price.test(pint)){ errors[errors.length] = "Illegal character in pint"; } if(!ck_price.test(halfpint)){ errors[errors.length] = "Illegal character in halfpint"; } if(!ck_price.test(bottle)){ errors[errors.length] = "Illegal character in Bottle/Spirit Price"; } if(!ck_price.test(offer)){ errors[errors.length] = "Illegal character in Offer price"; } if (errors.length > 0) { reportErrors(errors); return false; } return false; } function reportErrors(errors){ var msg = "Please Enter Valid Data...\n"; for (var i = 0; i<errors.length; i++) { var numError = i + 1; msg += "\n" + numError + ". " + errors[i]; } alert(msg); } For some reason i dont know why the javascript isnt reading the function even tho they are correctly named, the file is being read as the 1st test alert comes up. the 2nd one inside the function doesnt know. can anyone point in the right place or show me where i am going wrong. as you can see i have put both my entire form and and the java file up. so you can easily see what goes on #on a note i have multiple forms in a tab system if that has anything to do with it although i shouldnt see why it should. #oh and did i get my regex correct for ck_price e.g "9.99 or 10.99" and ck_abv eg "4.2 or 10.2 or 34" #im also using wampserver 2.1 with win7 and chrome if it's needed thanks ste Hi there, I'm absolute newbie in javascript, so the question may look not worth asking for you. Sorry for that. My situation is like that: I want to make a preview of form data using javascript. After the button "preview" is clicked I start showing div dialog which should contain data entered by users. The problem is that because my div dialog is coded in the same page as form I can get only default values. It means - after making some changes, they are not visible. To get and print the value of input I use this code: Code: <script type="text/javascript"> mytext = document.getElementById('name').value; document.write(mytext); </script> How it would be possible to update the values on "on click" event. Thank you very much for considering this question. I'm working on a image upload script. I have finish the PHP side of things now I'm ready for javascript to do its side of things. I wanting to have no page refresh the only way I know of doing this is pushing the form data to a iframe with the target property. I understand the concept of it but I'm not to sure how to write. Can someone help me out with this? Thank you! |