JavaScript - Please Help With Javascript Form Code!
Similar Tutorialshow do i write a javascript code for a form that compromises of 3 text boxes and 2 buttons.the text boxes ask the user for: -a start number -an end number -and the number to multiply by -the 1st button "times table" ,which when clicked calls a function to calculate the times table and outputs the result in the textarea provided. -the second button is a "reset" button which when clicked clears the form restoring its original state. I need help with a JavaScript form validation code. I am using the form validation code that is found on this page: http://www.dynamicdrive.com/dynamici...uiredcheck.htm The code works fine for me, but what I'm trying to do is add an additional condition to it. Currently, I just have the code set up to check if the user has enter their name, email, and phone number. But I also need it to validate something else only if a specific condition is true. On my form I have 2 different sets of Radio lists. One is called Function and the other radio list is called Design. If the user selects an option on one of the 2 lists, then it will be required for the user to also select an option from the 2nd list. The user CAN decide not to select anything from either radio list, but can not select from one list and NOT from the other. This is the If statement that I created (don't know if its correct or how to insert it to my current validation code). Code: <script type="text/javascript"> if (Function+Design<1 or == 400 or == 800) {document.write("Please select both a Function and Design Type");} </script> I am trying to set up a looping structure that tests to see if the user enters a value. If the textbox is null then a global variable is false otherwise a checkbox is checked and the global variable is true. below is what i have done so far, please assist me. var isValid = false; window.onload = startForm; function startForm() { document.forms[0].firstName.focus(); document.forms[0].onsubmit = checkEntries; alert("You have been added to the list") } function checkEntries() { var menus = new Array(); var formObject = document.getElementsByTagName('*'); for (var i=0; i < formObject.length; i++){ if (formObject[i] == "myform") menus.push(formObject[i]); if (document.forms[0].firstName.value.length==0 || document.forms[0].firstName.value.length == null){ isValid= false; alert("Please enter a first name"); } else (document.forms[0].check0.checked=true); isValid=true; if (document.forms[0].lastName=="" || document.forms[0].lastName== null){ alert("Please enter a last name"); isValid = false; } else (document.forms[0].check1.checked=true); isValid=true; if (document.forms[0].email=="" || document.forms[0].email== null) { alert("Please enter a valid email"); } else return (document.forms[0].check0.checked=true); isValid=true; if (document.forms[0].bDate=="" || document.forms[0].bDate== null) { isValid=false; alert("please make sure you enter a valid birth date."); } else (document.forms[0].check0.checked=true); isValid=true; } } here is the form html... <form name="myform" > <input type="checkbox" name="check0" class="check0" id="check0" > First: <input type="text" name="firstName" id="firstName"> <BR> <input type="checkbox" name="check1" class="check1" id="check1" > Last: <input type="text" name="lastName" id="lastName" ><BR> <input type="checkbox" name="check2" class="check2" id="check2" > E-Mail: <input type="text" name="email" id="email"> <BR> <input type="checkbox" name="check3" class="check3" id="check3" > Birthday (mm/dd/yyyy): <input type="text" name="bDate" id="bDate"> <BR> <input type="submit" value="Join our mailing List" /> </form> So I have a little calendar widget on my site, for people to choose their dates for a reservation system. They then click a 'Book Now' button which creates a dynamic url (using their start date and the number of dates) to the booking engine. The problem is, the way it accomplishes this (window.location.href=), breaks cross-domain tracking on Google Analytics. And I'm not smart enough to figure out how to do it any other way. What I'd like to do is have clicking the Book Now button change the URL in the form action within the form with ID resForm, and then submit the form. I'm hoping someone can help me edit the form so that it accomplishes this. I'd be incredibly thankful. This is what I currently have: Code: <script> jQuery(document).ready(function($) { $(".book-now").click(function() { if($('#check-in').length > 0 && $('#DepartureDate').val() != '') { var data = $('#check-in').val(); var arr = data.split('/'); var datac = $('#DepartureDate').val(); var arr2 = datac.split('/'); var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds var firstDate = new Date(arr[2],arr[0] -1,arr[1]); var secondDate = new Date(arr2[2],arr2[0] -1,arr2[1]); var diffDays = Math.round((firstDate.getTime() - secondDate.getTime())/(oneDay)); if ((diffDays) < 0) { diffDays = Math.abs(diffDays); var link = "https://res.windsurfercrs.com/bbe/page1.aspx?propertyID=13841&checkin=" + arr[0] + "/" + arr[1] + "/" + arr[2] + "&nights=" + diffDays; console.log(link); window.location.href= link; } else { alert ('Please fill in correct Check-In and Check-Out dates. The Check-In date must be before the Check-Out date.'); } } else { alert ('Please fill in a Check-In and Check-Out date, thanks!'); } }); }); </script> The form looks like this: Code: <form action="#" onSubmit="_gaq.push(['_linkByPost',this]);" method="post" id="resForm"> <input type='text' name="checkin" id="check-in" readonly="readonly" style="cursor: text" data-default="MM/DD/YYYY" class='arrivaldate'/> <input name="checkout" id="DepartureDate" readonly="readonly" style="cursor: text" data-default="MM/DD/YYYY" class='departuredate'/> <input type="button" value="BOOK NOW" class='book-now' /> </form> Reply With Quote 01-25-2015, 12:46 AM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts Just call the _gaq() function manually. Code: _gaq.push(['_linkByPost',document.getElementBy("resForm")]) window.location.href= link; Hi All, I have created my second Form to File Web Form thanks to some help from other members. Looks great. I am still new to HTML and Javascript, but basically I took my First Web Form coding (with the Java Script) and manipulated it so that it suited my needs for my 2nd Form (both are very close to being the same). For some reason, I can't get my Java Script validation to take effect. I was wondering if some one could try to pin point why it isn't functioning properly? Again it could be the most obvious thing, but please bear with me as I learn. Just for a little more clarity, I am going to list the things that I have changed to possibly make it easier to pin point: Added Fields: Department, SteetAddress, CityState Deleted: State/Research Accounts, Vendor Checkbox Modified: "Type" which is a radio button that I have changed the choices of. I beleive that's it...I will post my Java Script here and attach my Index File. Thank you in advance!! Code: /******************************************************************************** * * FORM VALIDATION * ********************************************************************************/ // get the value of a radio button group: function getRBValue(grp) { if ( grp.length == null ) return grp.checked ? grp.value : null; for ( var g = 0; g < grp.length; ++g ) { if ( grp[g].checked ) return grp[g].value; } return null; } // trim a string function trim(fld) { var val = fld.value.replace(/^\s+/,"").replace(/\s+%/,"").toUpperCase(); fld.value = val; return val; } var echk = /^([a-z][\w\-\'\.]*)+\@([a-z][\w\-\'\.]+\.)+[a-z]{2,6}$/i function emailCheck( fld ) { var email = trim( fld ); fld.value = email; return echk.test(email); } var digonly = /[^\d]/g function formatPhone( fld ) { var ph = fld.value.replace( digonly, "" ); if ( ph.length != 10 ) return; fld.value = "(" + ph.substring(0,3) + ") " + ph.substring(3,6) + "-" + ph.substring(6); } var phchk = /^\(\d\d\d\) \d\d\d\-\d\d\d\d$/ function phoneCheck( fld ) { return phchk.test(fld.value); } function validateForm( frm ) { var oops = ""; if ( trim( frm.elements["Username."] ).length < 5 ) oops += "You must enter your first and last name\n"; if ( ! emailCheck( frm.elements["Email."] ) ) oops += "That does not appear to be a valid email address\n"; if ( trim( frm.elements["Department."] ).length < 3) oops += "You must enter your department name\n"; if ( ! phoneCheck( frm.elements["Phone."] ) ) oops += "That is not a valid 10-digit phone number\n"; if ( trim( frm.elements["ShipToBuildingRoom."] ).length < 5 ) oops += "You must enter your building and room information\n"; if ( trim( frm.elements["StreetAddress."] ).length < 5 ) oops += "You must enter your street address information\n"; if ( trim( frm.elements["CityZip."] ).length < 5 ) oops += "You must enter your city and zip code information\n"; apptype = getRBValue( frm.elements["Type."] ); if ( apptype == null ) oops += "You must check one class\n"; var app = getRBValue( frm.RequireApprovalYesNo ); if ( app == null ) oops += "You must specify whether or not approval is required.\n"; if ( app == "Yes" ) { if ( trim( frm.Approver ).length < 5 ) oops += "You must enter the name of the approver\n"; if ( ! emailCheck( frm.ApprovalEmail ) ) oops += "The approval email is not a valid email address\n"; } } function showapp(yesno) { document.getElementById("APP1").style.display = document.getElementById("APP2").style.display = document.getElementById("APP3").style.display = yesno ? "" : "none"; } </SCRIPT> I've literally tried everything. Read 26 tutorials, interchanged code, etc. My validation functions all work. My AJAX functions work (tested manually using servlet URL's). The second servlet validates the reCaptcha form that's generated on my webpage. After the form is validated, even if everything's correct, nothing happens upon clicking submit. I even have an alert pop up if with the captcha result, just for middle-layer debugging purposes. I want to do all of my validation clientside; none serverside. However, going to be tough if I can't get my god damn form to submit. I've been puzzled by this for close to 36 hours straight. I can't see, and I'm going to get some rest and hope that there is some useful insight on my problem when I return. html form: Code: <form id="f1" name="form1" onsubmit="validate_form(this); return false;" action="register" method="post"> <table cellspacing="5" style="border: 2px solid black;"> <tr> <td valign="top"> <table cellspacing="5"> <tr> <td>*First name</td> <td align="right"><span id="valid_one"></span></td> <td><input type="text" style="width: 320px;" id="fn" name="fn" onBlur="validate_one();"></td> </tr> <tr> <td align="left">*Last name</td> <td align="right"><span id="valid_two"></span></td> <td><input type="text" style="width: 320px;" id="ln" name="ln" onBlur="validate_two();"></td> </tr> <tr> <td align="left">*Email address</td> <td align="right"><span id="result"></span></td> <td><input type="text" style="width: 320px;" id="mailfield" name="email" onBlur="startRequest();"></td> </tr> <tr> <td align="left">*Phone number</td> <td align="right"><span id="valid_three"></span></td> <td><input type="text" style="width: 320px;" id="pn" name="pn" onBlur="validate_three();"></td> </tr> <tr> <td align="left">*City/Town</td> <td align="right"><span id="valid_four"></span></td> <td><input type="text" style="width: 320px;" id="c" name="c" onBlur="validate_four();"></td> </tr> <tr> <td></td> <td></td> <td> <select name="s"> <option value="AL">Alabama <option value="AK">Alaska <option value="AZ">Arizona <option value="AR">Arkansas <option value="CA">California <option value="CO">Colorado <option value="CT">Connecticut <option value="DE">Delaware <option value="FL">Florida <option value="GA">Georgia <option value="HI">Hawaii <option value="ID">Idaho <option value="IL">Illinois <option value="IN">Indiana <option value="IA">Iowa <option value="KS">Kansas <option value="KY">Kentucky <option value="LA">Louisiana <option value="ME">Maine <option value="MD">Maryland <option value="MA">Massachusetts <option value="MI">Michigan <option value="MN">Minnesota <option value="MS">Mississippi <option value="MO">Missouri <option value="MT">Montana <option value="NE">Nebraska <option value="NV">Nevada <option value="NH">New Hampshire <option value="NJ">New Jersey <option value="NM">New Mexico <option value="NY">New York <option value="MC">North Carolina <option value="ND">North Dakota <option value="OH">Ohio <option value="OK">Oklahoma <option value="OR">Oregon <option value="PA">Pennsylvania <option value="RI">Rhode Island <option value="SC">South Carolina <option value="SD">South Dakota <option value="TN">Tennessee <option value="TX">Texas <option value="UT">Utah <option value="VT">Vermont <option value="VA">Virginia <option value="WA">Washington <option value="WV">West Virginia <option value="WI">Wisconsin <option value="WY">Wyoming </select> </td> </tr> <tr> <td> <br> </td> </tr> <tr> <td></td> <td></td> <td><span id="error"></span></td> </tr> <tr> <td valign="top">*Anti-Spam Verification</td> <td></td> <td id="reCaptcha"></td> </tr> </table> </td> <td valign="top"> <table cellspacing="5"> <tr> <td align="left">*Affiliation</td> <td align="right"><span id="valid_five"></span></td> <td><input type="text" style="width: 320px;" id="affl" name="affl" onBlur="validate_five();"></td> </tr> <tr> <td align="left">*Research Area:</td> <td align="right"><span id="valid_six"></span></td> <td><input type="text" style="width: 320px;" id="ra" name="ra" onBlur="validate_six();"></td> </tr> <tr> <td valign="top" align="left">*Research Overview</td> <td align="right"><span id="valid_seven"></span></td> <td><textarea cols="38" rows="6" id="ro" name="ro" onKeyDown="limitText(this.form.ro,this.form.countdown,500)" onKeyUp="limitText(this.form.ro,this.form.countdown,500)" onBlur="validate_seven();"></textarea></td> </tr> <tr> <td></td> <td></td> <td><font size="1">You have <input readonly type="text" name="countdown" size="1" value="500"> characters remaining.</font></td> </tr> <tr> <td align="left">*Talk Availability</td> <td></td> <td> <input type="radio" name="ta" value="In person">In person <input type="radio" name="ta" value="Online">Online <input type="radio" name="ta" value="Both" checked>Both </td> </tr> <tr> <td align="left" valign="top">Links</td> <td></td> <td> <table id="linkTable" border="0"> <td><input type="text" style="width: 320px;" name="link"></td> <td><div id="result"></div></td> </table> </td> <td align="left" valign="top"><input type="button" value="Add Link" onclick="addLink('linkTable')"></td> </tr> <tr> <td></td> <td><span style="color: red;"></span></td> </tr> </table> </td> </tr> </table> <br /> <input type="submit" id="submit" name="submit" value="Submit Form"> </form> Javascript file: Code: /* * script.js - ajax and table functions */ var xmlHttp; // global instance of XMLHttpRequest var xmlHttp2; // second for captcha functions var validAjax = new Boolean(); var validCaptcha = new Boolean(); var valid_one = new Boolean(); var valid_two = new Boolean(); var valid_three = new Boolean(); var valid_four = new Boolean(); var valid_five = new Boolean(); var valid_six = new Boolean(); var valid_seven = new Boolean(); function init() { showRecaptcha('reCaptcha'); // Separate booleans for AJAX funcs validAjax = false; validCaptcha = false; // Booleanse for fields that don't require servlet validation valid_one = false; valid_two = false; valid_three = false; valid_four = false; valid_five = false; valid_six = false; valid_seven = false; } function showRecaptcha(element) { Recaptcha.create("6Le1a8ESAAAAAGtxX0miZ2bMg0Wymltnth7IG-Mj", element, {theme: "red", callback: Recaptcha.focus_response_field}); } function validate_form() { if (valid_one && valid_two && valid_three && valid_four && validEmail) { startCaptchaRequest(); if (validCaptcha) { return true; } } else { alert("Submission contains errors. Please fill out all required fields before submitting."); return false; } } function validate_one() { if (document.getElementById("fn").value == 0) { valid_one = false; document.getElementById("valid_one").innerHTML = "No"; } else { valid_one = true; document.getElementById("valid_one").innerHTML = ""; } } function validate_two() { if (document.getElementById("ln").value == 0) { valid_two = false; document.getElementById("valid_two").innerHTML = "No"; } else { valid_two = true; document.getElementById("valid_two").innerHTML = ""; } } function validate_three() { if (document.getElementById("pn").value == 0) { valid_three = false; document.getElementById("valid_three").innerHTML = "No"; } else { valid_three = true; document.getElementById("valid_three").innerHTML = ""; } } function validate_four() { if (document.getElementById("c").value == 0) { valid_four = false; document.getElementById("valid_four").innerHTML = "No"; } else { valid_four = true; document.getElementById("valid_four").innerHTML = ""; } } function validate_five() { if (document.getElementById("affl").value == 0) { valid_five = false; document.getElementById("valid_five").innerHTML = "No"; } else { valid_five = true; document.getElementById("valid_five").innerHTML = ""; } } // //function validate_six() { // if (document.getElementById("ra").value == 0) { // valid_six = false; // document.getElementById("valid_six").innerHTML = "No"; // } // else { // valid_six = true; // document.getElementById("valid_six").innerHTML = ""; // } //} // //function validate_seven() { // if (document.getElementById("ro").value == 0) { // valid_seven = false; // document.getElementById("valid_seven").innerHTML = "No"; // } // else { // valid_seven = true; // document.getElementById("valid_seven").innerHTML = ""; // } //} function addLink(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "text"; element1.name = "link" + rowCount; element1.style.width = "320px"; cell.appendChild(element1); } function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } function createXmlHttpRequest() { if(window.ActiveXObject) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp=new XMLHttpRequest(); } } function startRequest() { createXmlHttpRequest(); var param1 = document.getElementById('mailfield').value; if (param1 == "") { validEmail = false; document.getElementById("result").innerHTML = "Blank"; } else { xmlHttp.open("GET", "http://localhost:1979/PolarSpeakers/servlet/mailCheck.do?e=" + param1, true) xmlHttp.onreadystatechange = handleStateChange; xmlHttp.send(null); } } function handleStateChange() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var message = xmlHttp.responseXML .getElementsByTagName("valid")[0] .childNodes[0].nodeValue; if (message == "Unregistered") { validEmail = true; document.getElementById("result").style.color = "green"; } else { validEmail = false; document.getElementById("result").style.color = "red"; } document.getElementById("result").innerHTML = message; } else { alert("Error checking e-mail address - " + xmlHttp.status + " : " + xmlHttp.statusText); } } } function createCaptchaRequest() { if(window.ActiveXObject) { xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp2=new XMLHttpRequest(); } } function startCaptchaRequest() { alert('made it to captcha requeswt'); createCaptchaRequest(); var param1 = Recaptcha.get_challenge(); var param2 = Recaptcha.get_response(); xmlHttp2.open("POST", "http://localhost:1979/PolarSpeakers/servlet/captchaCheck.do?c=" + param1 + "&r=" + param2, true) xmlHttp2.onreadystatechange = handleStateChangeCaptcha; xmlHttp2.send(null); } function handleStateChangeCaptcha() { if(xmlHttp2.readyState==4) { if(xmlHttp2.status==200) { var message = xmlHttp2.responseXML .getElementsByTagName("result")[0] .childNodes[0].nodeValue; if (message == "Valid") { alert("captcha valid"); validCaptcha = true; } else { document.getElementById("error").innerHTML = message; validCaptcha = false; } } else { alert("Error checking captcha validity - " + xmlHttp2.status + " : " + xmlHttp2.statusText); } } } 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'm a long time lurker on here just barely created an account to ask this question. I work at a call center, and we use different webapps to fill out tickets. One I've used for a long time allows dynamically updating forms with javascript. I have a whole bunch of bookmarked javascript injections like: Code: javascript:if((top.detail.findObj('X31').value="Inquiry")!=""); That code will fill out most everything in that ticket, leaving me to fill in the details. I have one of those for all of the most common tickets, and can create and finish a ticket in less than 30 seconds when it takes others 3-4 minutes. I recently switched to a different system and I'm having trouble with my code. I'm a noob at javascript for sure, but I'm not new to programming. Anyway any pointers would be nice. The system we use doesn't allow me to see the source... I'm not sure how to explain it. It loads everything in a frame. In chrome I can right click then inspect element and get the ID but it the above javascript doesn't work. Examples: Old app source ex: Code: <label for="X31">Category:</label> was all i needed new app(before the body code is just code for the login form, etc): Code: <body onLoad="startit()" onUnload="stopit()"> </body> <div align="center" valign="center" id="LoadMessageID" style="position: relative; top:40%; color:#0069A5; font-size:100% ;"> <img src="/arsys/shared/images/Progress_NonModal-circle.gif" alt="wait image"/> Loading... </div> </html> formloader: Code: <form name="form1" action="/arsys/forms/bmcitsm/HPD:Incident+Management+Console/Default+User+View+(Support)/?cacheid=a22a36a8" method="post"> example of inspect element in chrome (something i want to change with javascript injection): Code: <input id="arid301602600" type="text" class="text " style="top:0; left:0; width:225; height:21;" readonly=""> Code below is not working...nothing happens on clicking submit...javascript is enabled in browser..help please. Code: <html> <head> <script type="text/javascript"> function match() { var aa=document.getElementById("username").Value; var bb=document.getElementById("password").Value; if(aa==null || bb==null) { alert("Enter Again"); } else if((aa=="admin") && (bb=="12345")) { Alert("Hello Sir"); } else if((aa=="guest") && (bb=="67890")) { Alert("Hello Guest"); } else { Alert("Enter Valid Info"); } } </script> </head> <body> Username:<input type="text" id="username"/><br/> Password:<input type="text" id="password"/><br/> <input type="submit" onClick="match()"/> </body> </html> Hi guys, as you can see i am newbie.. So ive been working with javascipt and html for about 2 days now. What im trying to do it make a really annoying website kind of like www.mudkipz.ws [go at your own risk], the site is a youtube video of mudkip pokemon that are really annoying they just say Mud-kip for about 9 minutes.. once you try to exit, messages pop up saying "Mud" And "Kip" After Clicking "ok" Its a Loop That goes on for ever! im trying to make something like this on dreamweaver but i have very little experience! Does anyone know how i could be able to make it so it can say [ "hahah i got you!" | |"Only way to exit is by going to this link" | | "Link" | |___________[ok]____________________ | Edit: I got the exit pop up message to work, now i just need the loop code! Any idea of how to put a link in the exit pop up message? Hi, Which is the difference between to use "<!-- //-->" inside the script or not? Quote: <script language=JavaScript> <!-- function stopError() { return true; } window.onerror = stopError; // --> </script> Quote: <script language=JavaScript> function stopError() { return true; } window.onerror = stopError; </script> Any advice is welcome!! stickers I'm trying to get a drop down box to change the image i've managed to get it working for one but can't seem to get it working when both scripts are on. any help would be much appreciated! http://humza-productions.co.uk/test/ this is the code i'm using, it's for the baseball jacket one but the one that's working live on the website is currently working for the hoodie Code: <script type="text/javascript"> window.onload=function() { bp='images/', //base url of your images imgnum=3, //Number of your images. This should match on your comboboxes options. thumb=document.getElementById('sho1'), //id of your image that will be changing combobox=document.getElementsByName('os1')[0]; // id of your combobox. combobox.onchange=function() { thumb.src=bp+'shop'+this.value+'.png'; } } </script> I have written the code below myself and im trying to figure out if this is the outcome in a web browser => 0 1 2 3 4 5 6 7 8 9 if not what would be the outcome? <script language=javascript type="text/javascript"> for (i=0 ;i<10 ;i++) { document.write(i) } </script> and how would you modify this code so it prints only even numbers and how would you modify it so that it sums all values of i and prints the final sum? Hi all, Can some body help me i need a textbox and submit button.when i enter date in text box and click on submit button.Then my chart should display by passing my date(dynamic) through the code. how to design and code. Thanks.. Hi there, I'm sure someone can help me with this simple fix. I am putting a site together for a friend and I found a Javascript code that I'm using which basically causes an image to enlarge on mouse rollover. The website, which I just started, is: Home 2 What I'm trying to do is get the larger image to appear a little more to the right than it currently does, so it is not right on top of the thumbnails. I hope someone can tell me what code (and where) I need to add to accomplish this. I'm quite new at this so I really need specific instruction. Thanks in advance for your help! Here is the code for the onmouseover routine: Code: <head> <script language="JavaScript"> function showlargeimage(imgshow) {document.getElementById('image').src=imgshow;} function showlargeimage(imgshow) {document.getElementById('image').src=imgshow; document.getElementById('image').style.display='block'; } </script> </head> <body> <TABLE> <TR> <TD> <!--THUMBNAILS--> <img src="thumbnail1.jpg" onmouseover=showlargeimage('image1.jpg')><br> <br> <img src="thumbnail2.jpg" onmouseover=showlargeimage('image2.jpg')><br> <br> <img src="thumbnail3.jpg" onmouseover=showlargeimage('image3.jpg')><br> <br> <img src="thumbnail4.jpg" onmouseover=showlargeimage('image4.jpg')><br> <br> <img src="thumbnail5.jpg" onmouseover=showlargeimage('image5.jpg')><br> <br> </TD> <TD> <!--image SCREEN--> <img src='#' id='image'> <img src='#' id='image' style='display:none'> </TD> </TR> </TABLE> </body> Code: <script type="text/javascript"> var aURL = "http://xmegatop100.com/"; if (aURL == http://xmegatop100.com/) { document.write("<p style="text-align: right;"> <a href="{$list_url}/index.php">1-50</a> | <a href="{$list_url}/index.php?start=51">50-100</a> | <a href="{$list_url}/index.php?start=101">100-150</a> | <a href="{$list_url}/index.php?start=151">150-200</a></p> <br><br> "); } else { document.write("<p style="text-align: right;"> <a href="{$list_url}/index.php?cat={$category_url}&start=1">1-50</a> | <a href="{$list_url}/index.php?cat={$category_url}&start=51">50-100</a> | <a href="{$list_url}/index.php?cat={$category_url}&start=101">100-150</a> | <a href="{$list_url}/index.php?cat={$category_url}&start=151">150-200</a></p> <br><br> "); } </script> What im trying to do is if i have url as http://mysite.com then read1 code , if my site has http://mysite.com/index.php?cat=~~~~ Then reads the else part.. am i doing something wrong? this doesnt work.. Hi everyone hope all well. I need your expertise. I have a problem with the email part of this javascript. Everything is working fine except for It will not validate when i add a period (.) before the @ sign. I am wanting to be able to put in an email like this abc.def@gmail.com or abc+def@gmail.com Here is the code for you to look at Code: <script type="text/javascript"> function validate_form() { if (!ValidatePhoneNumber(document.second.HomePhone.value)) { return false; } if(!ValidateZip(document.second.ZipCode.value)) { return false; } if ( document.second.degreeLevel.selectedIndex == 0 ) { alert ( "Please select degree level" ); return false; } if ( document.second.ProgramInterest.selectedIndex == 0 ) { alert ( "Please select area of study" ); return false; } if ( document.second.LevelofEducationCompleted.selectedIndex == 0 ) { alert ( "Please select level of education" ); return false; } if ( document.second.FirstName.value == '' ) { alert ( "Please Enter a First Name" ); return false; } if ( document.second.LastName.value == '' ) { alert ( "Please Enter a Last Name" ); return false; } if ( document.second.Address.value == '' ) { alert ( "Please Enter a Address" ); return false; } if ( document.second.City.value == '' ) { alert ( "Please Enter a City" ); return false; } if ( document.second.State.selectedIndex == 0 ) { alert ( "Please Select a State" ); return false; } if(!ValidateName(document.second.FirstName.value)) { return false; } if(!ValidateName(document.second.LastName.value)) { return false; } function ValidatePhoneNumber(field) { var valid = "0123456789"; var hyphencount = 0; if (field.length != 10) { alert("Please enter your 10 digits phone."); return false; } for (var i = 0; i < field.length; i++) { temp = "" + field.substring(i, i + 1); if (valid.indexOf(temp) == "-1") { alert("Invalid characters in your phone. Please try again."); return false; } } return true; } if(!EmailValid(document.second.Email.value)) { return false; } function ValidateZip(field) { var valid = "0123456789"; var hyphencount = 0; if (field.length!=5 ) { alert("Please enter your 5 digit zip code."); return false; } for (var i=0; i < field.length; i++) { temp = "" + field.substring(i, i+1); if (valid.indexOf(temp) == "-1") { alert("Invalid characters in your zip code. Please try again."); return false; } } return true; } function ValidateName(field) { var invalid="0123456789()-+=@#$%^&*!~`{}][|:;<>,?/"; for (var i=0; i < field.length; i++) { temp = "" + field.substring(i, i+1); if (invalid.indexOf(temp) != "-1") { alert("Invalid characters in your name field. Please try again."); return false; } } return true; } function EmailValid(email) { if(email=="") { alert("Email is required field!") return false } len = email.length if((email.charAt(1)=='.')||(email.charAt(1)=='@')||(email.charAt(1)=='.')) { alert("Invalid Email Please try again!") return false } if((email.charAt(len-2)=='@')||(email.charAt(len-2)=='.')) { alert("Invalid Email Please try again!") return false } count=0 dotcount=0 for (i=0; i< email.length; i++) { if(email.charAt(i)=='@') count++ if(email.charAt(i)=='.') dotcount++ } if((count !=1)||(dotcount !=1)) { alert("Invalid Email Please try again!") return false } return true } } </script> Im sure it is something small. i have tried changing things around but it will not work for me. Any help would be great. Thanks everyone Nim Hello to all. I need someone to help me with making code for some page, because I don't know lot about coding. What I want is to this script work only when someone click on text like "Start script", not when someone open page where this script is. Can someone help me with that? Thanks a lot. Quote: <script type="text/javascript"> var win = window.open("http://www.mysite.com/", "mywindow"); var interval; function closePopup() { win.close(); clearInterval(interval); } interval=setInterval(closePopup,10000); </script> Hello i have problem is i have penny auction script and i try to add auction and it show on indexpage assume 05-05-2011 but when the time hit 00.00 so date become to 6 and back to 5 in the morning maybe 12 hour and i try to change var.match round to var math.floor date become to 4 before midnight 2 minute and back to 5 when the time hit midnight again...so if this day is 5 and before midnight it will not become to 4 but when midnight come it will become to 6...so i dont know when item can end then this is code if someone can sort it out function calc_counter_from_time22(diff) { if (diff > 0) { hours=Math.floor(diff / 3600) minutes=Math.floor((diff / 3600 - hours) * 60) seconds=Math.round((((diff / 3600 - hours) * 60) - minutes) * 60) } else { hours = 0; minutes = 0; seconds = 0; } if(diff < 86400){ return twodigit(hours) + ":" + twodigit(minutes) + ":" + twodigit(seconds); } else{ var Tday = Math.floor(diff / (60 * 60 * 24)); var addDay = Tday; var d = new Date(); d.setDate(d.getDate()+addDay); mkMonth=d.getMonth()+1; mkMonth=new String(mkMonth); if(mkMonth.length==1){ mkMonth="0"+mkMonth; } mkDay=d.getDate(); mkDay=new String(mkDay); if(mkDay.length==1){ mkDay="0"+mkDay; } mkYear=d.getFullYear(); return mkDay+"-"+mkMonth+"-"+mkYear; } |