JavaScript - Registration Form Trouble...
Hello,
i got a problem with form like this: https://www2.giocarena.com/it-IT/Register/Start.aspx It's possible to set the field Cod Referent????? I've tried with this: <form name="aspForm" method="post" action="https://www2.giocarena.com/it-IT/Register/Start.aspx" target="_blank"> <input type="hidden" name="ctl00$cphBaseContainer$ctl00$txt_code" value="44411122224322445"></input> <button type="submit"> Nome </button> </form> Thank you!Thank you, thank you! Similar Tutorials<?php require('connect.php'); if($_POST['reg1']=="Register") { $stmt1="insert into regtable(fname,lname,c_addr,p_addr,phno,email,dob,gender,qual,wexp,usertype,btype,uname,pwd) values('$name1','$name2','$add1','$add2','$phno1','$email1','$dob1','$gend1','$qual1','$wexp1','$uty pe','$batch1','$user','$upwd')"; $res1=mysql_query($stmt1,$con);} ?> <html> <head> <script type="text/javascript"> function validate() { f=0; if(document.getElementById('fname').value=="") { document.frm1.fname.style.border='1px solid red'; //document.frm1.fname.style.background='#FFFFCC'; document.frm1.fname.focus(); document.getElementById('d_fname').style.visibility="visible"; document.getElementById('d_fname').innerHTML="Enter First Name"; } else { f++; } if(document.getElementById('lname').value=="") { document.frm1.lname.style.border='1px solid red'; document.frm1.lname.focus(); document.getElementById('d_lname').style.visibility="visible"; document.getElementById('d_lname').innerHTML="Enter Last Name"; } else { f++; } if(document.getElementById('addr1').value=="") { document.frm1.addr1.style.border='1px solid red'; document.frm1.addr1.focus(); document.getElementById('d_cadd').style.visibility="visible"; document.getElementById('d_cadd').innerHTML="Enter Contact Address"; } else { f++; } if(document.getElementById('pno').value=="") {document.frm1.pno.style.border='1px solid red'; document.frm1.pno.focus(); document.getElementById('d_pno').style.visibility="visible"; document.getElementById('d_pno').innerHTML="Enter Phone Number"; } else { f++; } if(document.getElementById('emid').value=="") {document.frm1.emid.style.border='1px solid red'; document.frm1.emid.focus(); document.getElementById('d_emid').style.visibility="visible"; document.getElementById('d_emid').innerHTML="Enter Email Id"; } else {f++; } if(document.getElementById('day').value=="0") { document.frm1.day.style.border='1px solid red'; document.getElementById('d_dob').style.visibility="visible"; document.getElementById('d_dob').innerHTML="Invalid Date"; } else { f++; } if(document.getElementById('month').value=="0") { document.frm1.month.style.border='1px solid red'; document.getElementById('d_dob').style.visibility="visible"; document.getElementById('d_dob').innerHTML="Invalid Date"; } else { f++; } if(document.getElementById('year').value=="0") { document.frm1.year.style.border='1px solid red'; document.getElementById('d_dob').style.visibility="visible"; document.getElementById('d_dob').innerHTML="Invalid Date"; } else {f++; } if((document.getElementById("gender1").checked!=true) && (document.getElementById("gender2").checked!=true)) { //document.frm1.gender.style.border='1px solid red'; document.getElementById('d_gender').style.visibility="visible"; document.getElementById('d_gender').innerHTML="Select Gender"; } else { f++; } if((document.getElementById("qual1").checked!=true) && (document.getElementById("qual2").checked!=true) && (document.getElementById("qual3").checked!=true) && (document.getElementById("qual4").checked!=true)) { //document.frm1.gender.style.border='1px solid red'; document.getElementById('d_qual').style.visibility="visible"; document.getElementById('d_qual').innerHTML="Select Qualification"; } else {f++; } if(document.getElementById('wexp').value=="") { document.frm1.wexp.style.border='1px solid red'; //document.frm1.emid.focus(); document.getElementById('d_wexp').style.visibility="visible"; document.getElementById('d_wexp').innerHTML="Select Work Experience"; } else {f++;} if(document.getElementById('utype').value=="") { document.frm1.utype.style.border='1px solid red'; document.getElementById('d_utype').style.visibility="visible"; document.getElementById('d_utype').innerHTML="Select Usertype"; } else {f++; } if(document.getElementById('btype').value=="") { document.frm1.btype.style.border='1px solid red'; //document.frm1.emid.focus(); document.getElementById('d_btype').style.visibility="visible"; document.getElementById('d_btype').innerHTML="Select Batch"; } else {f++; } if(document.getElementById('uname').value=="") { document.frm1.uname.style.border='1px solid red'; document.frm1.uname.focus(); document.getElementById('d_uname').style.visibility="visible"; document.getElementById('d_uname').innerHTML="Enter Username"; } else {f++; } if(document.getElementById('pwd').value=="") { document.frm1.pwd.style.border='1px solid red'; document.frm1.pwd.focus(); document.getElementById('d_pwd').style.visibility="visible"; document.getElementById('d_pwd').innerHTML="Enter Password"; } else {f++; } if(document.getElementById('rpwd').value=="") { document.frm1.rpwd.style.border='1px solid red'; document.frm1.rpwd.focus(); document.getElementById('d_rpwd').style.visibility="visible"; document.getElementById('d_rpwd').innerHTML="Retype Password"; } else { f++; } if(f==15) {return true;} else { return false;} } /*function nameval() { var fnm=document.getElementById('fname').value; var pat=/\d\g; if(fnm.match(pat)) { alert("Only characters are allowed"); } }*/ function phonval() { var ph=document.getElementById("pno").value; var pat=/\s/g; var ex=/\D/g; str=""; if(ph.match(ex)) { // alert ("Invalid Phone"); str=str+ "Phone number should be digits"; document.getElementById('pno').value=""; } else if(ph.length!=10) { str=str+"Phone number should be of 10 digits" //alert("Phone number should be of 10 digits"); } /*else if(ph.match(pat)) { str=str+"Phone number cannot have blank spaces"; //alert("Phone number cannot have blank spaces"); } */ if(str.length!=0) { alert(str);} } function emailval() { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = document.getElementById('emid').value; if(reg.test(address) == false) { alert('Invalid Email Address'); return false; } } </script> </head> <body id="www-url-cz" onload="inactive()"> <h2><img src="design/icon-registration.png" height="70px" \>Registration Form</h2> <form name="frm1" method="post"> <table style="padding-top:50px;"> <tr> <th align="left">First Name</th> <td><input type="text" name="fname" id="fname" size="27" class="border"></td> <td class='err'><div id="d_fname"></div></td> </tr> <tr></tr> <tr> <th align="left">Last Name</th> <td><input type="text" name="lname" id="lname" size="27" class="border"></td> <td class='err'><div id="d_lname"></div></td> </tr> <tr></tr> <tr> <th align="left">Contact Address</th> <td><textarea rows="5" cols="20" name="addr1" id="addr1" class="border"></textarea></td> <td class="err"><div id="d_cadd"></div></td> </tr> <tr></tr> <tr> <th align="left">Permanent Address</th> <td><textarea rows="5" cols="20" name="addr2" id="addr2" class="border"></textarea></td> <td class='err'><div id="d_padd"></div></td> </tr> <tr></tr> <tr> <th align="left">Phone Number</th> <td><input type="text" name="pno" id="pno" size="27" class="border" onblur="phonval()"></td> <td class='err'><div id="d_pno"></div></td> </tr> <tr></tr> <tr> <th align="left">Email id</th> <td><input type="text" name="emid" id="emid" size="27" class="border" onblur="return emailval()"></td> <td class='err'><div id="d_emid"></div></td> </tr> <tr></tr> <tr> <th align="left">Date of Birth</th> <td colspan="3"> <select name="day" id="day" class="border" onchange="dat_day()"> <option value="0">Day</option> <script type="text/javascript"> for(i=1;i<=31;i++) { document.write("<option value="+i+">"+i+"</option>"); } </script> </select> <select name="month" id="month" class="border" onchange="dat_month()"> <option value="0">Month</option> <option value="1">Jan</option> <option value="2">Feb</option> <option value="3">Mar</option> <option value="4">Apr</option> <option value="5">May</option> <option value="6">June</option> <option value="7">Jul</option> <option value="8">Aug</option> <option value="9">Sep</option> <option value="10">Oct</option> <option value="11">Nov</option> <option value="12">Dec</option> </select> <select name="year" id="year" class="border" onchange="dat_year()"> <option value="0">Year</option> <script type="text/javascript"> for(i=1975;i<=1996;i++) { document.write("<option value="+i+">"+i+"</option>") } </script> </select><div class="err" id="d_dob"></div> </td> <!--<td class="err"><div id="d_dob"></div></td>--> </tr> <tr></tr> <!--<tr> <th align="left">Age</th> <td><input type="text" name="age id="age" size="27" class="border"></td> </tr>--> <tr> <th align="left">Gender</th> <td colspan="3"> Male<input type="radio" value="male" name="gender" id="gender1"> Female<input type="radio" value="female" name="gender" id="gender2"> <div class="err" id="d_gender"></div> </td> <!--<td class='err'><div id="d_gender"></div></td>--> </tr> <tr></tr> <tr> <th align="left">Qualification</th> <td colspan="5"> SSLC<input type="radio" value="sslc" name="qual" id="qual1"> Plus Two<input type="radio" value="plus_two" name="qual" id="qual2"> Degree<input type="radio" value="degree" name="qual" id="qual3"> PG<input type="radio" value="pg" name="qual" id="qual4"> <div class="err" id="d_qual"></div> </td> <!--<td class='err'><div id="d_qual"></div></td>--> </tr> <tr></tr> <tr> <th align="left">Work Experience(in years)</th> <td colspan="2"><select name="wexp" id="wexp" class="border"> <option value=''>Select One</option> <script type="text/javascript"> for(var i=0;i<=15;i++) { document.write("<option value="+i+">"+i+"</option>"); } </script> <option>More than 15 years</option> </select> <div id="d_wexp" class="err"></div> </td> <!--<td class='err'><div id="d_wexp"></div></td>--> </tr> <tr></tr> <tr> <th align="left">User Type</th> <td><select name="utype" id="utype" class="border"> <option value=''>Select One</option> <option value='admin'>Administrator</option> <option value='trainer'>Trainer</option> <option value='trainee'>Trainee</option> </select> </td> <td class='err'><div id="d_utype"></div></td> </tr> <tr></tr> <tr> <th align="left">Batch Type</th> <td><select multiple="multiple" size="0" name="btype" id="btype" class="border"> <option value=''>Select One</option> <?php while($row=mysql_fetch_array($result)) { ?> <option value="<?php echo $row['batchtypeid']?>"><?php echo $row['batchtype'] ?></option> <?php } ?> </select> </td> <td class='err'><div id="d_btype"></div></td> </tr> <tr></tr> <!-- <tr> <th align="left">Batch Code</th> <td> <select multiple="multiple" size="0" name="bcode" id="bcode" class="border">--> <!--<option value="">Select One</option>--> <!--</select> </td> <td class='err'><div id="d_bcode"></div></td> </tr>--> <tr></tr> <tr> <th align="left">Username</th> <td><input type="text" name="uname" id="uname" size="27" class="border"></td> <td class='err'><div id="d_uname"></div></td> </tr> <tr></tr> <tr> <th align="left">Password</th> <td><input type="password" name="pwd" id="pwd" size="27" class="border"></td> <td class='err'><div id="d_pwd"></div></td> </tr> <tr></tr> <tr> <th align="left">Retype Password</th> <td><input type="password" name="rpwd" id="rpwd" size="27" class="border"></td> <td class='err'><div id="d_rpwd"></div></td> </tr> <tr> <td></td> </tr> <tr></tr> <tr> <td></td> <td><input type="submit" value="Register" name="reg1" id="reg1" onclick="return validate()" ></td> </tr> </table></form></div> I have been working on this code for a few days now. It is suppose to: 1. Remove the default values placed in the textarea. 2. Enter only numbers in the Phone Number field. 3. Verify that the passwords entered in the password fields are the same. 4. Verify everything is filled out, one of the radio buttons is selected and at least one of the check boxes are checked using a Submit() function as well as clear the fields using a Reset() function. I have the first two figured out and was able to get the password to verify once but can not get it to work again with any code. I am also unable to figure out a code that will call all these funtions together in the end to verify everything is filled out and not have the default words count as the field being filled. The idea of a default text is also kind of strange to me. I figured out how to remove the text entered as the value, but how do you get JavaScript to know that is the default and not an option to be used? Code: <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registration</title> <!--Create a registration form, similar to what you may encounter when registering for an online Web site. Include three sections: Personal Information, Security Information, and Preferences. In the Personal Information section, add name, e-mail address, and telephone fields. Include default text in the name and e-mail text boxes, but write some code that removes the default text from each text box when a user clicks it. Write code for the telephone field that prevents users from entering any values except for numbers. In the Security Information section, add password and password confirmation fields. Write code that ensures that the same value was entered into both fields. Also add a security challenge question selection list and a security answer text box that the Web site will use to help identify a user in the event that he or she loses his or her password. The security challenge selection list should contain questions such as What is your mother's maiden name?, What is the name of your pet?, and What is your favorite color?. In the Preferences section, add radio buttons that confirm whether a user wants special offers sent to his or her e-mail address. Also, include check boxes with special interests the user may be interested in, such as entertainment, business, and shopping. Add submit and reset buttons that call submit() and reset() event handler functions when they are clicked. The submit() event handler function should ensure that the user has entered values into each text box, and that the values submitted are not the same as the default text. The submit() event handler function should also ensure that the user selects a security challenge question, selects a radio button to confirm whether he or she wants special offers sent to his or her e-mail address, and selects at least one interest check box. Submit the form to the FormProcessor.html script (there is a copy in your Cases folder for Chapter 5). Save the document as Registration.html. --> <script language="javascript" type="text/javascript"> // This JavaScript removes default values form field function doClear(theText) { if (theText.value == theText.defaultValue) { theText.value = "" } } // This JavaScript allows characters exept numbers function AcceptLetters(objtextbox) { var exp = /[^\D]/g; objtextbox.value = objtextbox.value.replace(exp,''); } // This JavaScript allows numbers only function AcceptDigits(objtextbox) { var exp = /[^\d]/g; objtextbox.value = objtextbox.value.replace(exp,''); } //This JavaScript confirms everything is filled out function confirmSubmit() { var submitForm = window.confirm("Are you sure you want to submit the form?"); if (document.registar[0].name.value == "Name" || document.registar[0].name.value == "" || document.registar[0].e_mail.value == "E-Mail Address" || document.registar[0].e_mail.value == "" || document.registar[0].phone.value == "" || document.registar[0].phone.value == "" || document.registar[0].password1.value == "" || document.registar[0].password2.value == "" || document.registar[0].sq_answer.value == "Question Answer") { window.alert("You must enter all fields above."); return false; } else return true; } </script> </head> <body> <h1>Registration Page</h1> <form name="registar " method="post" onsubmit="return confirmSubmit()"> <h3>Personal Information</h3> Name:<br /> <input type="text" name="name" value="Name" maxlength=10 id="letters" onFocus="doClear(this)" onkeyup="AcceptLetters(this)" /> <br /> E-Mail:<br /> <input type="text" name="email" value="E-mail Address" onFocus="doClear(this)" /> <br /> Phone Number:<br /> <input type="text" name="phoneNumber" maxlength=10 id="txttest" onFocus="doClear(this)" onkeyup="AcceptDigits(this)" /> <br /> <h3>Security Information</h3> Password:<br /> <input type="password" name="password1" /><br /> Confirm Password:<br /> <input type="password" name="password2" /><br /> <DIV ID="password_result"> </DIV> Security Question:<br /> <select id="selection"><br /> <option value=0>Please Choose One</option> <option value=1>What is your favorite food?</option> <option value=2>What is your Mother's maiden name?</option><br /> <option calue=3>What is your pets name?</option><br /> <option value=4>What is the name of your High School?</option><br /> </select><br /> Answer<br /> <input type="text" name="sq_answer" value="Question Answer" onFocus="doClear(this)" /><br /> <h3>Preferences</h3> Yes<input type="radio" name="confirmAnswer" value="Yes"/>No<input type="radio" name="answer" value="No" />Would you like any special offers sent to your E-mail address?<br /> <h5>Interests</h5> <input type="checkbox" name="interest" value="check"/>Entertainment<br /> <input type="checkbox" name="interest" value="check"/>Shopping<br /> <input type="checkbox" name="interest" value="check"/>Business<br /> <input type="checkbox" name="interest" value="check"/>Exercise<br /> <br /> <input type="submit" value="Submit"/> <input type="reset" value="Reset"/> </form> </body> </html> I am trying to submit my form and receive a success message that go's away. My form validation is working fine and I receive the email, but the echo back to json is giving my error message instead of my success message. This is my first try doing this and am brand new to javascript. If anyone could please help me figure out what is wrong or tell me how to rewrite it, I would be much obliged. Code: function submitForm(formData) { $.ajax({ type: 'POST', url: 'bookings.php', data: formData, dataType: 'json', cache: false, timeout: 7000, success: function(data) { $('form #response').removeClass().addClass((data.error === true) ? 'error' : 'success') .html(data.msg).fadeIn('fast'); if ($('form #response').hasClass('success')) { setTimeout("$('form #response').fadeOut('fast')", 5000); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { $('form #response').removeClass().addClass('error') .html('<strong>There was an error. Please use the above information and contact us directly.</strong>').fadeIn('fast'); }, complete: function(XMLHttpRequest, status) { $('form')[0].reset(); } }); }; Hey guys, I am pretty new at javascript but am trying to learn. Here is a problem I have encountered. I have made a form with various input fields and a set of radio buttons which change the parameters of the form. One of the radio button sets is "Search by X" and "Search by Y" I want the action parameter for the form to change depending on whethere X or Y is selected Code: <FORM name=ENTRY_FORM onSubmit="return Check();" action="pointMeTo()" method="get"> If X is selected then action="http://site.com//doSomething.action" if Y is selected then action="http://site.com//doSomethingElse.action" The way I attempted to do the above(and I am not claiming this to be most efficient, just what comes to mind at the moment) is to create three functions and two global variables. Code: var xyToggler = false; var out = ""; function toggleX(){ xyToggler = false; } function toggleY(){ xyToggler = true; } function pointMeTo(){ if(xyToggler){ out="http://site.com//doSomething.action" } else out="http://site.com//doSomethingElse.action" } Thats the javascript part, now on the html form part: Code: <FORM name=ENTRY_FORM onSubmit="return Check();" action="pointMeTo()" method="get"> <!-- Stuff --> <input type="radio" name="choose" id="X" NAME="rbXY" value="X" onClick="toggleX()" checked/><label for="X">X</label> <input type="radio" name="choose" id="Y" NAME="rbXY" value="Y" onClick="toggleY()" /><label for="Y">Y</label> The logic seems like it would work to me, but when I try it out the results that are expected to come depending on the parameters X or Y are not displayed, in fact nothing is displayed but a msg saying that there is no such link. So I am assuming that means that the function is not properly assigning the corresponding links to the action= field in the form. Many thanks to whoever can spot my error or give me some advise! All the best. I'm trying to create a popup sign up form that will only popup every week. I don't want it to popup every time someone visits the site. I'm new to Javascript as a whole and can't seem to figure out how to set a cookie for a week and if there is no cookie (or the cookie has expired) it will popup automatically. If anyone can point out what I'm doing wrong it would be greatly appreciated. I feel like I'm so close and that the solution is staring me in the face. Here's the code that I have so far: function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + 5); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function checkCookie() { var username=getCookie(exdate); if (exdate!=null && exdate!="") { //Do Nothing } else { $(document).ready(function() { var id = '#dialog'; //Get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Set heigth and width to mask to fill up the whole screen $('#mask').css({'width':maskWidth,'height':maskHeight}); //transition effect $('#mask').fadeIn(1000); //Get the window height and width var winH = $(window).height(); var winW = $(window).width(); //Set the popup window to center $(id).css('top', winH/100-$(id).height()/2); $(id).css('left', winW/2-$(id).width()/2); //transition effect $(id).fadeIn(1000); $(id).animate({top:"+=300px"},1000); //if close button is clicked $('.window .close').click(function (e) { //Cancel the link behavior e.preventDefault(); $('.window').animate({right:"+=150px"}).animate({left:"1500px"}).fadeOut(50); $('#mask').hide(); }); //if NO Thanks button is clicked $('.window .noThanks').click(function (e) { //Cancel the link behavior e.preventDefault(); $('.window').animate({right:"+=150px"}).animate({left:"1500px"}).fadeOut(50); $('#mask').hide(); }); //if mask is clicked $('#mask').click(function () { $(this).hide(); $('.window').hide(); }); function hideHolder() { $('.place-holder').hide(); } function showHolder() { if($('.name-field').val() == '') { $('.place-holder').show() } } $('.name-field').focus(hideHolder); $('.name-field').blur(showHolder); $('.place-holder').click(function () { $('.name-field').trigger('focus'); }); }); } } Thank you for your help. :-) I'm trying to make an xhtml form that validates itself through a javascript function. I have the form up but for some reason I can't get it to validate. I'm not even sure if I linked things correctly. Here's what I have: the xhtml file <?xml version = ″1.0″ encoding = ″utf-8″ ?> <!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> <script src="gas24.js" type="text/javascript"></script> <h2> Registration Form </h2> <title> Javascript Form Validation Homework </title> </head> <body> <table border=""> <form name="validation_form" method="post" onsubmit="return validate()"> <tr> <td> <t>Name: <input type="text" name="YourName" size="10" maxlength="10"/> </td> </tr> </br> <tr> <td> E-mail Address: <input type="text" name="YourEmail" size="10" maxlength="24"/> </td> </tr> </br> <tr> <td> Password: <input type="password" name="YourPassword" size="10" maxlength="10"/> </td> </tr> </br> <tr> <td> Re-Type Password: <input type="password" name="passwordConfirmed" size="10" maxlength="10"/> </td> </tr> </br> <tr> <td> Your Gender: <input type="radio" name="MaleBox" Value="Male"> Male <input type="radio" name="FemaleBox" Value="Female"> Female </td> </tr> </br> <tr> <td> Comments: <input type="text" name="Comments" size="100" maxlength="500" value=""/> </td> </tr> <tr> <td> <input type="submit" value="Submit"/> </td> </tr> </form> </table> <p></p> </body> </html> The javascript file: I've tried two things. This: <SCRIPT LANGUAGE="JavaScript"> function validation() { var x=document.forms["validation_form"]["YourName"].value; if (x==null || x=="") { alert("First name must be filled out"); return false; } } And this: function validation() if ( document.validation_form.YourName.value == "" ) { alert( "Please type your name."); valid = false; } if ( document.validation_form.YourPassword.value =! "document.validation_form.Confirm.value" ) { alert ( "Please confirm your password." ); valid = false; } I would greatly appreciate it if somebody could tell me what I'm doing wrong. Hi all, I am new to JS and usually learn by studying code posted online and modify it to have it do what I need. Recently, I used a totaling plugin for an online ordering form which does the below: item1 qty(user input text) * preset price = total price item2 qty(user input text) * preset price = total price item3 qty(user input text) * preset price = total price -------------------------------------------------------- grand total -------------------------------------------------------- The JS code which passes the grandTotal variable is as below: Code: function ($this){ // sum the total of the $("[id^=total_item]") selector var sum = $this.sum(); $("#grandTotal").text( // round the results to 2 digits "₹" + sum.toFixed(2) ); } The problem I have is the above grandTotal displays the final value when put into a table like below: Code: <td align="right" id="grandTotal"></td> But I am unable to make it work by passing it into a variable within the form fields. I would like to do something like this: Code: <input type="text" name="grandTotal" id="grandTotal" readonly="readonly" /> Can somebody please help me fix this? Any help will be greatly appreciated. Thank you. Sup gents Can someone please tell me whats wrong with this code? The user is supposed to input a pass and script needs to check the array to see if such a pass exists in the array and confirm. Im building a sign in system for my website and this is the first step. Dont mind the global values in the beginning i plan to use them later while applying restrictions. Code: <html> <head> <script type ="text/JavaScript"> var counter = 0; var trial = 0; var base = 0; var choice = 0; var array2[] = {"1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009"}; var searchKey = searchform.inputVal.value; function pass() { for (var i =0; i < array2.length; i++) { if (array2[i] == searchkey ) searchform.result.value = "correct password"; } else return -1; } </script> </head> <body> <form name = "searchform" action = ""> <p>Enter password<br /> <input name = "inputVal"/> <input name = "search" type = "button" value = "Search" onclick = "pass()" /><br /></p> <p>Result<br /> <input name = "result" type = "text" size = "30" /></p> </form> </body> </html> This is a bit of a lazy post but hey, Currently i have an awful lot of checks that run the same check on different variables. Simple Request... Can anyone see an obvious way (which i have clearly missed) to clean up and reduce the amount of code in the below. Code: <? // required code for every page. require($_SERVER['DOCUMENT_ROOT'] . '/scripts/required.php'); // end of required code for every page if(isset($_POST['sbmt'])) { // get variables $new_user = trim($_POST['user']); $new_pass = $_POST['newpass']; $con_pass = $_POST['conpass']; $new_fname = trim($_POST['fname']); $new_email = $_POST['email']; $con_email = $_POST['conemail']; $agree = $_POST['agree']; $level = $_POST['level']; $ip = @$_SERVER['REMOTE_ADDR']; // add slashes $new_user = addslashes($new_user); // encrypt $new_pass_e = hash('ripemd160',$new_pass); $con_pass_e = hash('ripemd160',$con_pass); // check username exists // connect to database $con = mysql_connect(DBHOST, DBUSER, DBPASS); if(!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db(DBNAME, $con); // get row for user $result = mysql_query("SELECT * FROM tUsers WHERE username='$new_user'"); $row = mysql_fetch_array($result); // kill connection mysql_close($con); // check username exists if($row['username']!=null) $user_error = 'Username already in use.<br />'; else $user_error = null; // check email is available // connect to database $con = mysql_connect(DBHOST, DBUSER, DBPASS); if(!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db(DBNAME, $con); // get row for user $result = mysql_query("SELECT * FROM tUsers WHERE email='$new_email'"); $row = mysql_fetch_array($result); // kill connection mysql_close($con); // check email is available if($row['email']!=null) $email_error = 'Email already in use.<br />'; else $email_error = null; // check lengths if(strlen($new_user)<3) $user_len_error = 'Username must be at least 3 characters<br />'; else $user_len_error = null; if(strlen($new_pass)<6) $pass_len_error = 'Password must be at least 6 characters<br />'; else $pass_len_error = null; if(strlen($new_fname)<6) $fname_len_error = 'Your name must be at least 6 characters<br />'; else $fname_len_error = null; // preg matches if(!preg_match('/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $new_email)) $email_preg_error = "Email is not valid.<br />"; else $email_preg_error = null; if(!preg_match('/[a-zA-Z]+\s+[a-zA-Z]+/',$new_fname)) $fname_preg_error = 'Name must containt at least one space.<br />'; else $fname_preg_error = null; // check matches if($new_pass != $con_pass) $pass_match_error = 'The passwords do not match.<br />'; else $pass_match_error = null; if($new_email != $con_email) $email_match_error = 'The emails do not match.<br />'; else $email_match_error = null; // build error list $errorlist = $user_error; $errorlist .= $email_error; $errorlist .= $user_len_error; $errorlist .= $pass_len_error; $errorlist .= $fname_len_error; $errorlist .= $email_preg_error; $errorlist .= $fname_preg_error; $errorlist .= $pass_match_error; $errorlist .= $email_match_error; // set expirey to a month $expire = 0; // set error list cookie setcookie('errorlist',$errorlist,$expire,'/'); // reload register.php header('Location:' . URL . '/register.php'); } ?> The required file is just a series of defines for items like the dbhost, dbusername, dbname, url etc etc. Cheers p.s. I want to add an if statement for if $errorlist=null then do bla else bla... in order for errorlist to be null... do i actually need to define the individual error messages as null. That could get rid of a lot of: else $<error name>=null; I'm pretty sure I can but i'd like to check first. Anybody help to start out this code: Create a "nag" counter that tells users to register. Save the counter in a cookie and display a message reminding users to register every fifth time they visit your site. There are four other parts to this task that I know how to do. I cannot find anything close to this in our book referencing a nag-counter or something similar to it. Thanks, in advance. Regards, AO5431 I have a piece of JavaScript code that should validate that a username field is not empty or null and that a telephone field is in the correct format using event handler registration. It seems to be validating fine but if there is an error it still manages to submit. HTML Code: <html> <head> <script type = "text/javascript" src = "js/validator.js" > </script> </head> <body> <form id = "decorForm" action = ""> <table border = "0"> <tr> <th>Username: </th> <td> <input type = "text" id = "myUserName" size = "15" maxlength = "15"/> </td> </tr> <tr> <th>Telephone: </th> <td> <input type = "text" id = "telephone" name = "telephone" size = "15" maxlength = "13"/> <br /> (999)999-9999 </td> </tr> <tr> <td> <input type = "submit" value = "Submit" /> </td> <td> <input type = "reset" value = "Reset" /> </td> </tr> </table> </form> <script type = "text/javascript" src = "js/validatorr.js" > </script> </body> </html> JAVASCRIPT (validator.js) Code: function chkUser() { // Verifies that the UserName field is not empty. var myUserName = document.getElementById("myUserName"); if (myUserName.value == "" || myUserName.value == null) { alert ("Please enter a Username!"); return false; } else { return true; } } function chkTelephone() { // Verifies that the Telephone field value is in the correct format. var tel = document.getElementById("telephone"); var pos = tel.value.search(/^\(\d{3}\)\d{3}-\d{4}$/); if (pos != 0) { alert ("Please enter telephone number in the following format: (999)999-9999"); return false; } else { return true; } } function chkFields() { // Verifes all fields and returns boolean to event handler // The event handler function if (chkUser() && chkTelephone()) { return true; } else { return false; } } JAVASCRIPT (validatorr.js) Code: //Register the event handlers for validator.js document.getElementById("decorForm").onSubmit = chkFields; I am trying to use this as an example. I have a form that does not validate when in a modal. Here is the page: http://www.varsitytrainers.com/purchase1.html It works well. It does not work when viewed on this page: http://www.varsitytrainers.com/bosto...ltrainers.html - Then click "Apply Now" and then click "Featured Membership" then click "Submit" You will see that the validation does not take place. I have been banging my head against the desk for days now. Please help. OK i really hope someone can help me because this has put a complete halt to what I'm doing right now. i have various images in a 12x12 grid with names such as x1y1, x2y2, ect I need to check what x1y1's image SRC is. I have been trying stuff like this: var xpos = 1 var ypos = 1 var IMAGENAME = "x" + xpos + "y" + ypos blah = ('document.' + IMAGENAME + '.src') if (blah == "something.gif") { do what i want } Just doesn't work, nor has the 80 other things I've tried lol. Can anyone help me out? Hello, I am researching an issue in a rather big app which displays pdf files in IE window. The issue is that inside javascript code we call 'window.setTimeout( win.focus() ...)' (for the child window), but it doesn't come into focus every time, seems a bit random when it does and does not come into focus. At present I wrote a much smaller app + javascript to reproduce the issue, but it does not manifest in same way. Specifically this is the confusing part: window.setTimeout( function() {win.focus(); win.moveTo( 200 , 200 ); } , 500 , "JavaScript" ); the 'win' does move, but never comes into focus. Any ideas about why the focus function does not accomplish what I'm trying to do? Here's the code of my simplified app + html + javascript: JAVASCRIPT: Code: var win; function f(s) { website="http://machine/apache/jsfnu/mytest" + s + ".txt"; if (!win) win = window.open( website , "thetest" , "toolbar=yes,resizable=yes"); else { win.url = website; } win.navigate(website); win.focus(); window.setTimeout( function() {win.focus(); win.moveTo( 200 , 200 ); } , 500 , "JavaScript" ); } function emitApplet() { document.write("<APPLET CODE=\"mytest.class\" archive=\"mytest.jar,netscape.jar\" NAME=\"myApplet\" MAYSCRIPT HEIGHT=1000 WIDTH=1000> </APPLET>"); } function window_onUnload() { } JAVA code: Code: import netscape.javascript.*; import java.awt.*; import java.awt.event.*; public class mytest extends java.applet.Applet implements ActionListener { Button nextButton; Button prevButton; int _page=1; public void init() { System.err.println("init started"); setLayout(new FlowLayout()); System.err.println("setLayout done"); nextButton = new Button("Next!"); System.err.println("next button created"); prevButton = new Button("Prev!"); System.err.println("prev button created"); add(prevButton); System.err.println("prev button added"); add(nextButton); System.err.println("next button added"); nextButton.addActionListener(this); System.err.println("next button action"); prevButton.addActionListener(this); System.err.println("prev button created"); } public void actionPerformed(ActionEvent evt) { if (evt.getSource() == nextButton) { doButton(++_page); } else if (evt.getSource() == prevButton) { doButton(--_page); } } public void doButton(int page) { JSObject win = JSObject.getWindow(this); JSObject doc = (JSObject) win.getMember("document"); JSObject loc = (JSObject) doc.getMember("location"); String s = (String) loc.getMember("href"); String []args = new String[1]; args[0] = (new Integer(page)).toString(); win.call("f", args); } public void paint (java.awt.Graphics g) { g.drawString("Hello, World9!",50,25); } } HTML: Code: <script type="text/javascript" src="StartTest.js"> </script> <html> <head> <title>try</title> </head> <body bgcolor="#fdf8ed" text="black" language="Javascript" onload="window_onUnload()"> <center> <script type="text/javascript"> emitApplet(); </script> </center> </body> </html> I am working on converting something and this is what I have come up with: http://www.msnsportsnet.com/content/ravenstest.htm The width of the original file was 845 px, I needed to change it to 235 px though. As I have knocked the size down of everything, I noticed the arrows are now not working correctly. The arrow only goes to the right once and to the left once, I need to it to go to the right and left multiple times. Here is the javascript file that I have been working with: Code: // gameday scroller function scrollGameday(dir) { var cssDir= (dir<0) ? 'right':'left'; var scrollWidth = 235; var scrollSpeed = 235; var scrollWrapLeft = parseInt($("#gameScroller").css("left")); if(okScroll == false) { return; } if(cssDir == "left") { if($("#arrowRight").hasClass("disable")) $("#arrowRight").removeClass('disable'); if(currentPane <= 1) { return; } else { scrollWrapLeft = (scrollWrapLeft + (dir * scrollWidth)); okScroll = false; $("#gameScroller").animate({left: scrollWrapLeft+"px"}, scrollSpeed, function() { okScroll = true; }); currentPane = currentPane-dir; if(currentPane <= 1) { if(!$("#arrowLeft").hasClass("disable")) $("#arrowLeft").addClass('disable'); } } } if(cssDir == "right") { if($("#arrowLeft").hasClass("disable")) $("#arrowLeft").removeClass('disable'); if(currentPane >= paneCount) { if(!$("#arrowRight").hasClass("disable")) $("#arrowRight").addClass('disable'); return; } else { scrollWrapLeft = (scrollWrapLeft + (dir * scrollWidth)); okScroll = false; $("#gameScroller").animate({left: scrollWrapLeft+"px"}, scrollSpeed, function() { okScroll = true; }); currentPane = currentPane-dir; if(currentPane >= paneCount) { if(!$("#arrowRight").hasClass("disable")) $("#arrowRight").addClass('disable'); } } } checkCurrentPane(currentPane); } function checkCurrentPane(currentPane) { alert('check'); if(currentPane == 1) { if(!$("#arrowLeft").hasClass("disable")) $("#arrowLeft").addClass('disable'); } else if(currentPane == paneCount) { if(!$("#arrowRight").hasClass("disable")) $("#arrowRight").addClass('disable'); } } $("#gameScroller").each(function (i) { var scrollWidth = 235; var newLeftPos = (i * scrollWidth)+"px"; $("#gameScroller:eq("+i+")").css("left", newLeftPos); var items = $('.game'); $('#gameScroller').css('width', items.length * items[0].offsetWidth + 'px'); $("#arrowLeft").click(function() { scrollGameday(3); return false; }); $("#arrowRight").click(function() { scrollGameday(-2); return false; }); }); if("#gameScroller") { var okScroll = true; var currentPane = 1; var paneCount = Math.ceil(($(".game").length) / 10); if(paneCount <= 1) { $(".arrow").className = $(".arrow").className + ' disable'; } else if (paneCount > 1) { $("#arrowLeft").addClass('disable'); } preScroll(); } function preScroll() { var games = $('.game'); for(n=0; n<games.length; n++) { if(games[n].className.match('active')) { var currFrame = Math.floor(n/10); scrollGameday(-currFrame); } } } This is the CSS file: http://www.msnsportsnet.com/content/ravens.css Thank you very much and any help is much appreciated. I am not great at using JavaScript but I am working on it. I really need help with my script. I can't seem to find out why my images won't load correctly. I am trying to get a 2 part radio button selection to show different pictures for every combination of colors you can choose. So if I was to pick black and black a black_black.jpg picture will pop up and black_white.jpg will pop up for a black and white selection. Please if anybody can help I could really use it right now. Thanks! Code: <html> <body> <form name = "myform"> <img id = "myImage" src = "MyDefaultImage.jpg"> <br><br> Barrels: -------- Inserts:<br> Black <input type = "radio" name = "col1" value = "black" onclick = "showImage();"> Black <input type = "radio" name = "col2" value = "black" onclick = "showImage();"><br> White <input type = "radio" name = "col1" value = "white" onclick = "showImage();"> White <input type = "radio" name = "col2" value = "white" onclick = "showImage();"><br> Orange <input type = "radio" name = "col1" value = "orange" onclick = "showImage();"> Orange <input type = "radio" name = "col2" value = "orange" onclick = "showImage();"><br> Red <input type = "radio" name = "col1" value = "red" onclick = "showImage();"> Red <input type = "radio" name = "col2" value = "red" onclick = "showImage();"><br> </form> <br> <br> <script type = "text/javascript"> function showImage() { var A = 0; var B = 0; for (var i=0; i <document.myform.col1.length; i++) { if (document.myform.col1[i].checked) { A = document.myform.col1[i].value; } } for (var u=0; u <document.myform.col2.length; u++) { if (document.myform.col2[u].checked) { B = document.myform.col2[u].value; } } var x = A + "_" + B; if (x>0) { var picture = x + ".jpg"; document.getElementById("myImage").src = picture; } } </script> </body> </html> I am working on converting something and this is what I have come up with: http://www.msnsportsnet.com/content/ravenstest.htm However, the width of that is 845 px and I wanted it to drop down to 650 px and make the arrows have the same effect as they did with the 845 px. First I moved the 845 to 650 in the css file, then changed the 845 to 650 in the JS files, I have been unable to figure this out though. If someone could please help that would be great! This is the JS file that I tried to edit: http://www.baltimoreravens.com/includes/jsbin/ravens.js This is the css file: http://www.msnsportsnet.com/content/ravens.css Hi, the cookies I am trying to read are values from a form that were stored. The problem I am having is that one value form the form, the value is 5000, was stored as a cookie but I cannot read it. When I display it, it returns: [object HTMLInputElement]. The code for storing the value is this: Code: document.cookie = "bankRoll=" + encodeURIComponent(money) + "; expires=" + expireDate.toUTCString(); , where money = 5000. The code for reading the cookies is this: Code: var cookies = decodeURIComponent(document.cookie); var cookieNumber = new Array(10); cookieNumber = cookies.split("; "); for(var i = 0; i < cookieNumber.length; ++i) { var equalPos1 = cookieNumber[i].search("="); if (cookieNumber[i].substring(0, equalPos1) == "firstName") firstName = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "lastName") lastName = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "pCode") pCode = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "bankRoll") bankRoll = cookieNumber[i].substring(equalPos1 + 1); if (cookieNumber[i].substring(0, equalPos1) == "lastVisit") lastVisit = cookieNumber[i].substring(equalPos1 + 1); } The only one that does not display properly is the variable bankroll. All the others return the proper value. I would like to know how to fix my code so that the value 5000 is displayed. Someone tell me where I'm going wrong. I'm trying to print out the month/year ? Code: <html><head> <SCRIPT language=JavaScript> var dateNow = new Date(); var monthNow = dateNow.getMonth(); var yearNow = dateNow.getYear(); function MakeArray(n) { this.length = n return this } monthNames = new MakeArray(12) monthNames[1] = "Janurary" monthNames[2] = "February" monthNames[3] = "March" monthNames[4] = "April" monthNames[5] = "May" monthNames[6] = "June" monthNames[7] = "July" monthNames[8] = "August" monthNames[9] = "Sept." monthNames[10] = "Oct." monthNames[11] = "Nov." monthNames[12] = "Dec." function customDate(oneDate) { var theMonth = monthNames[oneDate.getMonth() +1] } </SCRIPT> </head><body><script type="text/javascript"> document.write(theMonth + "/" + yearNow); </script> </body></html> http://icant.co.uk/sandbox/countdown.html Hi, I am trying to understand the countdown above but I am having some problems. I am trying to remove some of the fields under preferences, I just want to show "Time in Seconds" and "warning start" and not any of the other fields. When I try to remove something from the script the entire thing just stop working. So my question is simple, how do I hide/remove fields under preferences without breaking the countdown? |