JavaScript - Javacript Alert Box Redirect To False Ie9?
Okay, on my website I have some javascript code I'm using to make the user input required text. If they don't enter info in all the required fields an alert box appears (nothing new)..
The issue is, when you click okay, it redirects to a page and just says "false." It only does this in IE9.. Chrome has no issues.. Any idea? or resolutions? website issue he https://pcexpresstechs.com/get_started.html here is the code: Code: function verify() { var themessage = "You are required to complete the following fields: \n"; if (document.input.first.value=="") { themessage = themessage + " - First Name"; } if (document.input.last.value=="") { themessage = themessage + " - Last Name"; } if (document.input.email.value=="") { themessage = themessage + " - Email Address"; } if (document.input.phone.value=="") { themessage = themessage + " - Phone"; } //alert if fields are empty and cancel form submit if (themessage == "You are required to complete the following fields: \n") { document.input.submit(); } else { alert(themessage); return false; } } Similar TutorialsI am getting double Alert prompts for a single form: The alert pops up the first time, then when I click OK, the same one pops open again. I think my code should do the alert once when it hits "else window.alert(sameWarning) and the stop when it reaches "return false()"; but it seems return false() is causing the alert twice. Maybe because I have two forms on one page; yet, they have two separate function names ("signinForm()" and "saveSignUp()")and call two separate forms (forms[0] and forms[1])? I think my code is correct, but I can't figure it out at this point. Any help would be appreciated. Thanks in advance! Code: <script type="text/javascript"> //FIRST FUNCTION FOR FORMS[0] function signinForm(){ // var sameWarning = "The required fields were not submitted for the following error(s). \n \n"; var warningLogin = "The following field(s) require an entry: \n \n"; var sameWarning = warningLogin; var userName = document.forms[0].userName.value; var pswd = document.forms[0].pswd.value; if(userName == ""){ sameWarning += " - First Name \n"; } if(pswd == ""){ sameWarning += " - Password \n"; } if (warningLogin == sameWarning){ return true; } else { window.alert(sameWarning); } return false; } //SECOND FUNCTION CALL FOR FORMS[1] function saveSignUp(){ // var warning = "The required fields were not submitted for the following error(s). \n \n"; var warning = "The following field(s) require an entry: \n \n"; var same = warning; var firstName = document.forms[1].firstName.value; var lastName = document.forms[1].lastName.value; var email = document.forms[1].email.value; var phone = document.forms[1].phoneNumber.value; if(firstName == ""){ //firstName.style.backgroundColor="red"; warning += " - First Name \n"; } if(lastName == ""){ warning += " - Last Name \n"; } if(email == ""){ warning += " - Email \n"; } if(phone == ""){ warning += " - Work Phone \n"; } if(phone < 5 ){ warning += " - Must be a numberssss \n"; } if (warning == same){ return true; } else { alert(warning); } return false; } </script> HTML Code: <h1>Login</h1> <form method="post" onsubmit="return signinForm();" action="" > <input type="text" placeholder="Username/Email" name="userName"> <input type="password" placeholder="Password" name="pswd" id="pswd"> <input type="submit" onclick="signinForm();" value="Sign In"> </form> <h1>Sign Up!</h1> <form method="post" onsubmit="return saveSignUp()" action="" > <input type="text" placeholder="First Name" name="firstName"> <input type="text" placeholder="Last Name" name="lastName"> <input type="text" placeholder="Email" name="email"> <input type="text" placeholder="Phone Number" name="phoneNumber"> <input type="submit" onclick="saveSignUp();" class="button wide" value="Request an Account"> </form> *UPDATE Fixed! After I removed the onclick in the button, the double alerts went away. Apparently, I was I was firing off two events (calling the javascript twice) with both the onsubmit and the onclick. Just wondering: 1. Is "onsubmit" a special event handler just for button "type=submit" vs onlclick can be used for any element? 2. Is there a preference among developers to use onclick vs. onsubmit? 3. Is there an order of precedence for method calls over submit calls (the onclick goes first, then it automatically fires the submit call to the function too)? Hello, I have stack of images arrange one behind another, when ever i click on them current image should flip down, image is flipping down but its parent container is staying at same position. Due to that i am not able to perform action on other images. i have chosen the option of providing lesser z index value to parent element so that it will not cause problem to perform event on other images. But still it is not working. I am able to add z index value but when running the code both flipping and adding z index to parent is executing at one time. Due to that animation is not coming in a right way. i want to know, How i can execute code one after another, example when flipping image is completed then only i want to add z index value to parent element (f1_container) SO that it will not cause problem for other images. Please help <div id="f1_container" class="f1_container"> <div id="f1_card" class="shadow"> <div class="front face"> <img src="img/8.jpg"/> </div> <div class="back face center"> <img src="img/1.jpg"/> </div> </div> </div> var flipImage=document.querySelectorAll('.shadow'); for(j=0; j<flipImage.length; j++){ var currentFlipImage=flipImage[j]; currentFlipImage.addEventListener('click', function(event){ var currentElement=event.currentTarget; //this should be executed first currentElement.style.webkitTransform='rotateX(-120deg)'; and this one should execute after flipping is completely done this.parentNode.style.zIndex=-100; },false); } hi, I need to modify IE print settings(paper size, print orientation) automatically, by javascript and can not use ActiveX control or reduce IE security setting. Can any one tell me how to implement this function,Thanks. I have an user table like this:- guid | username | password | firstname | lastname | location | emailad dress | userrole -----------------------------------+----------+----------------------------------+-----------+-----------+----------+-------- ------+--------------- 8024259764dc3e8ee0fb6f5.84107784 | james | 827ccb0eea8a706c4c34a16891f84e7b | james | bond | NY | ny@live .com | administrator 18689183644dc3e91571a364.71859328 | saty | 250cf8b51c773f3f8dc8b4be867a9a02 | saty | john | NY | hk@fd.c om | administrator 2644885344cecd6f2973b35.63257615 | admin | 21232f297a57a5a743894a0e4a801fc3 | System | Generated | | | administrator (3 rows) now my postgre query for delete the row .... $query = "delete from users where username!= 'admin' and guid='".$guid."'"; $result = pg_query($conn, $query); ?> <script type="text/javascript"> alert("Cannot delete this .\n It is system generated(s)."); </script> <?php (1)when I delete the user name one by one then delete occurs in my page userlist.php, I donot want to delete admin so i use username!= 'admin' in where condition as shown above. (2)now when I del any username(3 rows) from user table then alert occurs & it delete from userlist.php after that my page userlist.php is blank. Finaly when i refresh the page then my admin username seen.. when i use return true; function then only alert generate .. delete doesnot occurs ... Actauly i want:- (1)if user is not admin then it delete from userlist.php ... nd also i m continue on this page ... like when james and saty want to delte their acount ..as given in table. (2)if user is admin then alert generate nd i m continue on this page. i m tired now plz help me .... so can anyone put the best condition in my coding. Hello all. I have started working on my companies website, http://www.janwyck.net Within it is an order form for ordering paint sundries from a shopping cart using javascript and cookies. After the customer selects a few items and fills out the form if they hit Submit, it brings up a pop-up that says First False. The only way I know to show you guys is to show the page code, I am sorry: Code: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage 2.0"> <title>Janwyck Decorating Center</title> </head> <script language="javascript"> index = 0; function format(val, post) { var decpoint; var begin; var end; var valstr; var temp_char; valstr = "" + val; //alert('valstr = ' + valstr); decpoint = valstr.indexOf(".") if (decpoint != -1) { //alert('decpoint = ' + decpoint); begin = valstr.substring(0,decpoint); end = valstr.substring(decpoint+1,valstr.length); //alert('begin = ' + begin + '\nend= ' + end); } else { begin = valstr; end = ""; } if (end.length < post) {while (end.length < post) { end += "0"; } } end = end.substring(0,post); //alert('begin = ' + begin + '\nend= ' + end); return (begin+"."+end); } function orderSubmit(type) { if (type == 'order') {if ( ! ( (document.order.order_type.checked) || checkRequired() )) { // checkCardNumber(); ENTRY HERE alert('first true'); document.order.form_action.value = type; document.order.submit(); return true; } else { alert('first false'); return false; } } } var infowin = null; function copyToShipping() { if (document.order.same_flag.checked) { document.order.ship_name.value = document.order.name_first.value+' '+document.order.name_last.value; document.order.ship_address1.value = document.order.address1.value; document.order.ship_address2.value = document.order.address2.value; document.order.ship_city.value = document.order.city.value; document.order.ship_state.value = document.order.state.value; document.order.ship_zip.value = document.order.zip.value; document.order.ship_country.value = document.order.country.value; document.order.ship_phone.value = document.order.phone.value; } } function disableSameFlag() { document.order.same_flag.checked = false; } function checkRequired() { if (!document.order.name_first.value.length || !document.order.name_last.value.length || !document.order.email.value.length || !document.order.address1.value.length || !document.order.city.value.length || !document.order.state.value.length || !document.order.zip.value.length || !document.order.country.value.length) { alert('You have not completed all required fields:\n' + 'Please complete the Name, Address, City,\n' + 'County, Post Code, and Country in the\n' + 'Customer Info section'); return true; } else { return false; } } <!-- --> </script><!-- --><a name="top"></a> <body background="images/thisback.gif" bgcolor="#FFFFFF" text="#000000" onLoad=parent.refresh_ship_details(parent.ship_details) onUnload=parent.add_ship_details(parent.ship_details)> <center> <script language="javascript"> <!-- hide if (self==parent){document.write('<font color=#ff000><b>This is a frame element, click <a href=index.htm> here </a>for correct page</b></font>')}; <!-- end hide --> </script> <p><font color="#FF0000" size="7"><i>Janwyck Order Form</i><br> </font></p> <table border="0" width=400> <tr> <td align="center" bgcolor="#FF0000"><font color="#FFFFFF"><b>Please wait while the scripted order form is generated....... </b></font> </td> </tr> </table> <p><font size="6">Order Form</font> <br> <!-- HEY!!! PUT YOUR EMAIL ADDRESS IN THE LINK BELOW SO THEY CAN WRITE TO YOU --> <b>In the event of difficulty with this script please email us direct on <a href=mailto:janwyckpaint@gmail.com>Janwyck Paint</a> or call us on (706)865-2811</b> </p> <!-- YOU CAN PUT YOUR EMAIL ADDRESS IN THE FORM COMMAND BELOW AND THE --> <!-- THEN IT WILL BE SENT TO YOU AS A SIMPLE MAILTO GUESTBOOK FORM --> <!-- IF YOU DO THAT - BE SURE TO ADD THE COMMAND enctype="plain/text" --> <!-- IN ORDER TO DELINEATE THE MAIL FOR YOU --> <!-- YOU CAN ALSO USE TE .PL FILE AS A CGI TO HELP WTH THE MAIL. SEE THE TUTORIAL --> <!-- FOR MORE ON HOW THAT IS DONE --> <form action="MAILTO:janwyckpaint@gmail.com" method="POST" name="order" enctype="plain/text"> <input type="hidden" name="Order Form" value="Order Forms - Order Form"><input type="hidden" name="recipient" value="janwyckpaint@gmail.com"><input type="hidden" name="redirect" value="thanku.htm"><input type="hidden" name="retailer" value="Janwyck Decorating Center"><input type="hidden" name="form_action" value="order"> <script language="javascript"> <!-- hide from Browsers document.write('<table width=400><td align=center>'); document.write('<table width=400 ><tr><tr><td align=right colspan=3 BGCOLOR=#FF9999><font size=+2>Running Total : $ </td><td colspan=3 BGCOLOR=FF9999> <input type=text name=total size=6 value='+ format(parent.all_order_totals(),2) + '></font></td><tr>'); document.write('<td colspan=6 align=center><b>This is your Order Total so far<br>.</td></tr><tr></table>'); if (parent.items_ordered == 0) document.write('<font color=#000080><b>You have not ordered any items so far<b></font>'); if (parent.item_num > 0) { for (i =1;i < parent.item_num;i++) { if (parent.itemlist[i].quan > 0) {index = index + 1; document.write('<a href='+ parent.itemlist[i].url + '><i><b> review : </b></i></a><input size=10 type=text name= ' + parent.itemlist[i].code + ' value= ' + parent.itemlist[i].code + '><input size=6 type=text name= ' + parent.itemlist[i].code + ' value=' + parent.itemlist[i].price + '><input size=20 type=text name= ' + parent.itemlist[i].code + ' value= '+ parent.itemlist[i].desc + '><input size=2 type=text name= ' + parent.itemlist[i].desc + ' value= '+ parent.itemlist[i].quan + '><br>'); } } } <!-- end hiding --> </script> <table border="0" width=400> <tr> <td align="center" colspan="6" bgcolor="#FF9999"><b>Comments & Additional Information <br><font color=#ffff00>Can be written in the box below</font><br> </b></td> </tr> <tr> <td colspan="6"><center><textarea name="comments" rows="10" cols="40"></textarea></center></td> </tr> </table> <!-- Customer Info Table --> <table border="0" cellpadding="0" cellspacing="0" bgcolor="#00FFFF" width=400> <tr> <td align="center" colspan="5" bgcolor="#CCFFFF"><b>Customer Information / Details</b></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>First Name: </b></td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="30" maxlength="30" name="name_first"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>Last Name:</b> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="30" maxlength="30" name="name_last"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>Email Address:</b> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="30" maxlength="60" name="email"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>Address:</b> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="30" maxlength="60" name="address1"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="30" maxlength="60" name="address2"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>City:</b> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="30" maxlength="30" name="city"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>County:</b> </td> <td bgcolor="#CCFFFF"><input type="text" size="8" maxlength="10" name="state"></td> <td align="right" bgcolor="#CCFFFF"><b>Post Code:</b> </td> <td bgcolor="#CCFFFF"><input type="text" size="9" maxlength="10" name="zip"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>Country:</b> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="25" maxlength="25" name="country" value="UK"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>Phone:</b> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="25" maxlength="25" name="phone"></td> </tr> <tr> <td align="right" colspan="2" bgcolor="#CCFFFF"><b>Fax:</b> </td> <td colspan="3" bgcolor="#CCFFFF"><input type="text" size="25" maxlength="25" name="fax"></td> </tr> <tr> <td align="center" colspan="5" bgcolor="#CCFFFF"><input type="checkbox" name="mail_list">Check here to be included on our mailing list </td> </tr> </table> <p align="center"><br> <p align="center"><br> <!-- Order Method Table --> </p> <table border="0" cellspacing="0" width=400> <tr> <td align="center" colspan="5" bgcolor="#CCFFFF"><font size="4"><b>Choose Order Method:</b></font></td> </tr> <tr> <td align="center" colspan="5" bgcolor="#CCFFFF"> <font size="2">Phone Call: <input type="radio" name="order_type" value="phone"></font> </td> </tr> <tr> <td align="center" colspan="5" bgcolor="#CCFFFF"><a href="options.htm" target=navigate> </td> </tr> </table> <p><br> <p><br> <p align="center"><br> <input type="button" value="Place Order" onclick="orderSubmit('order')"> <input type="reset" value="Reset Address Details"> </p> </form> </td></table> </center> </p> </body > </html> I hate posting that much code. I think though that it might be related to: Code: function orderSubmit(type) { if (type == 'order') {if ( ! ( (document.order.order_type.checked) || checkRequired() )) { // checkCardNumber(); ENTRY HERE alert('first true'); document.order.form_action.value = type; document.order.submit(); return true; } else { alert('first false'); return false; } } } But I am not quiet sure. ANy help I may get is greatly appreciated as the site is very close to going live and this is my BIG problem. Does anyone know why I am not getting an alert on an empty form INPUT value? Code: if (document.forms["form"]["targetname"].value == "" && document.forms["form"]["unknownname"] == false) { alert ("What ever"); return false; } document.forms["form"]["targetname"] is a form INPUT text document.forms["form"]["unknownname"] is a form INPUT checkbox I suspect the problem is due to 'false'.. but I can't figure out why. Hi I've managed to change the border color whenever someone clicks on another link on my page but because I need to use return false to keep the color it is stopping the link from going to that page; Code: <script type="text/javascript"> function changeColor(color) { document.getElementById("nav").style.borderColor = color; } </script> <a href="index.php" onclick="changeColor('red') ;return false">HOME</a> <a href="about.php" onclick="changeColor('blue') ;return false">ABOUT</a> <a href="contact.php" onclick="changeColor('orange') ;return false">CONTACT</a> Any help would be appreciated, I've only recently got into JS Cheers I have the following form: Quote: <form action="/cgi-bin/script.cgi" method="POST" onsubmit="check_create()"> <fieldset> <legend>Create project</legend> Type <input id="type" type="text" name="type" size="20" /><br/> Name <input id="project" type="text" name="project" size="20" /><br/> Language to use <input id="language" type="text" name="language" size="20"/><br/> <input type="hidden" name="profile" value="[% profile %]"/> <input type="submit" value="Create" /> </fieldset> </form><br/> and check_create function is: Quote: function check_create() { var type = document.getElementById('type').value; var pname = document.getElementById('project').value; var language = document.getElementById('language').value; if ((type == '') || (pname == '') || (language == '')) { alert('You must complete form'); return false; } else alert('Ok'); } The problem is that return false doesn't work, but form lanch /cgi-bin/script.cgi. Where is the problem? Why return false doesn' work? Regards, savio please help i am working on a widget for samsung solstice phone . it is a animated clock. got code from another widget but i can not figure out how to make it show 12 hour time instead if 24 it looks like it contains the code just note sure how to make it work Here is the code below. Any help would be great. /* * jDigiClock plugin 2.1 * var Digital; var hours; var minutes; var month; var date; var day; var year; var currDate; var timeUpdate; var ampm = false; var vvv = 0; var MonthsOfYear = new Array(12); MonthsOfYear[0] = "01"; MonthsOfYear[1] = "02"; MonthsOfYear[2] = "03"; MonthsOfYear[3] = "04"; MonthsOfYear[4] = "05"; MonthsOfYear[5] = "06"; MonthsOfYear[6] = "07"; MonthsOfYear[7] = "08"; MonthsOfYear[8] = "09"; MonthsOfYear[9] = "10"; MonthsOfYear[10] = "11"; MonthsOfYear[11] = "12"; var DaysOfWeek = new Array(7); var DaysOfWeekS = new Array(7); var MonthNames = new Array(12); switch(GetLanguage()){ case "en": DaysOfWeek[0] = "Sunday"; DaysOfWeek[1] = "Monday"; DaysOfWeek[2] = "Tuesday"; DaysOfWeek[3] = "Wednesday"; DaysOfWeek[4] = "Thursday"; DaysOfWeek[5] = "Friday"; DaysOfWeek[6] = "Saturday"; DaysOfWeekS[0] = "Sun"; DaysOfWeekS[1] = "Mon"; DaysOfWeekS[2] = "Tue"; DaysOfWeekS[3] = "Wed"; DaysOfWeekS[4] = "Thu"; DaysOfWeekS[5] = "Fri"; DaysOfWeekS[6] = "Sat"; MonthNames[0] = 'Jan'; MonthNames[1] = 'Feb'; MonthNames[2] = 'Mar'; MonthNames[3] = 'Apr'; MonthNames[4] = 'May'; MonthNames[5] = 'Jun'; MonthNames[6] = 'Jul'; MonthNames[7] = 'Aug'; MonthNames[8] = 'Sep'; MonthNames[9] = 'Oct'; MonthNames[10] = 'Nov'; MonthNames[11] = 'Dec'; break; case "es": DaysOfWeek[0] = "Sunday"; DaysOfWeek[1] = "Monday"; DaysOfWeek[2] = "Tuesday"; DaysOfWeek[3] = "Wednesday"; DaysOfWeek[4] = "Thursday"; DaysOfWeek[5] = "Friday"; DaysOfWeek[6] = "Saturday"; DaysOfWeekS[0] = "Sun"; DaysOfWeekS[1] = "Mon"; DaysOfWeekS[2] = "Tue"; DaysOfWeekS[3] = "Wed"; DaysOfWeekS[4] = "Thu"; DaysOfWeekS[5] = "Fri"; DaysOfWeekS[6] = "Sat"; MonthNames[0] = 'Jan'; MonthNames[1] = 'Feb'; MonthNames[2] = 'Mar'; MonthNames[3] = 'Apr'; MonthNames[4] = 'May'; MonthNames[5] = 'Jun'; MonthNames[6] = 'Jul'; MonthNames[7] = 'Aug'; MonthNames[8] = 'Sep'; MonthNames[9] = 'Oct'; MonthNames[10] = 'Nov'; MonthNames[11] = 'Dec'; break; default: DaysOfWeek[0] = "Sunday"; DaysOfWeek[1] = "Monday"; DaysOfWeek[2] = "Tuesday"; DaysOfWeek[3] = "Wednesday"; DaysOfWeek[4] = "Thursday"; DaysOfWeek[5] = "Friday"; DaysOfWeek[6] = "Saturday"; DaysOfWeekS[0] = "Sun"; DaysOfWeekS[1] = "Mon"; DaysOfWeekS[2] = "Tue"; DaysOfWeekS[3] = "Wed"; DaysOfWeekS[4] = "Thu"; DaysOfWeekS[5] = "Fri"; DaysOfWeekS[6] = "Sat"; MonthNames[0] = 'Jan'; MonthNames[1] = 'Feb'; MonthNames[2] = 'Mar'; MonthNames[3] = 'Apr'; MonthNames[4] = 'May'; MonthNames[5] = 'Jun'; MonthNames[6] = 'Jul'; MonthNames[7] = 'Aug'; MonthNames[8] = 'Sep'; MonthNames[9] = 'Oct'; MonthNames[10] = 'Nov'; MonthNames[11] = 'Dec'; } function init(){ getTime(); //setTimeout("getTime()", 5000); } function getTime() { Digital = new Date(); hours = Digital.getHours(); minutes = Digital.getMinutes(); month = MonthsOfYear[Digital.getMonth()]; date = Digital.getDate(); day = Digital.getDay(); year = Digital.getFullYear(); var now = new Date(); var now_hours, now_minutes, old_hours, old_minutes, timeOld = ''; now_hours = now.getHours(); now_minutes = now.getMinutes(); if (ampm) { var am_pm = now_hours > 11 ? 'pm' : 'am'; now_hours = ((now_hours > 12) ? now_hours - 12 : now_hours); document.getElementById('iap').src = 'images/clock/' + am_pm + '.png'; } now_hours = ((now_hours < 10) ? "0" : "") + now_hours; now_minutes = ((now_minutes < 10) ? "0" : "") + now_minutes; date = ((date < 10) ? "0" : "") + date; // data - verificar formato: dd/mm/yyyy ou yyyy/dd/mm ou outro //currDate = date + "/" + month + "/" + year; /* dd/mm/aaaa Fri 23 Apr 2010 mm/dd/aaaa Fri Apr 23 2010 aaaa/mm/dd 2010 Apr 23 Fri aaaa/dd/mm 2010 23 Apr Fri */ currDate = Digital.toLocaleDateString(); var ary = new Array(); ary = currDate.split(" "); if(isNaN(ary[0])){ currDate = DaysOfWeekS[day]+', '; if(isNaN(ary[1])){ currDate += MonthNames[Digital.getMonth()] + ' ' +date+', '+year; }else{ currDate += date + ' ' + MonthNames[Digital.getMonth()] + ' ' + year; } }else{ if(isNaN(ary[1])){ currDate = year + ' ' + MonthNames[Digital.getMonth()] + ' ' + date + ', ' + DaysOfWeekS[day]; }else{ currDate = year + ' ' + date + ' ' + MonthNames[Digital.getMonth()] + ', ' + DaysOfWeekS[day]; } } timeOld += '<div id="hours"><div class="line"></div>'; timeOld += '<div id="hours_bg">'; timeOld += '<img id="hours_bg1" src="images/clock/clockbg1.png" /></div>'; timeOld += '<img src="images/clock/clockbg-blank.png" id="fhd" class="first_digit" />'; timeOld += '<img src="images/clock/clockbg-blank.png" id="shd" class="second_digit" />'; timeOld += '</div>'; timeOld += '<div id="minutes"><div class="line"></div>'; if (ampm) { timeOld += '<div id="am_pm"><img src="images/clock/apm.png" /></div>'; } timeOld += '<div id="minutes_bg"><img id="minutes_bg1" src="images/clock/clockbg1.png" /></div>'; timeOld += '<img src="images/clock/clockbg-blank.png" id="fmd" class="first_digit" />'; timeOld += '<img src="images/clock/clockbg-blank.png" id="smd" class="second_digit" />'; timeOld += '</div>'; document.getElementById('clock').innerHTML = timeOld; document.getElementById("date").innerHTML = currDate; document.getElementById('fhd').src = 'images/clock/' + now_hours.substr(0,1) + '.png'; document.getElementById('shd').src = 'images/clock/' + now_hours.substr(1,1) + '.png'; document.getElementById('fmd').src = 'images/clock/' + now_minutes.substr(0,1) + '.png'; document.getElementById('smd').src = 'images/clock/' + now_minutes.substr(1,1) + '.png'; //setTimeout("getTime()",(60 - now.getSeconds()) * 1000); setTimeout("getTime()", 4000); } function GetLanguage(){ try { return widget.sysInfo.getLanguage(); }catch(E){ return "pt"; } } Consider the following test page: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Contenteditable Test</title> <style> .test {} [contenteditable="true"] { outline:1px solid red; } </style> <script> function listen(id, eventName, func) { el = document.getElementById(id); if (el.addEventListener) el.addEventListener(eventName, func, false); else el.attachEvent('on'+eventName, func); } window.onload = function() { listen('root', 'click', toggle); listen('test', 'click', toggle); } function toggle(e) { var el = getTarget(e).parentNode; if (el.id == 'test') { el.setAttribute('contenteditable', 'true'); } else { el.setAttribute('contenteditable', 'false'); /* The style of the element should change accordingly. *** BUT *** it DOESN'T!!!! */ alert(el.getAttribute('contenteditable')); /* Confirm that contenteditable is 'false'. */ } } function getTarget(e) { return (window.event == undefined ? e : window.event).target; } </script> </head> <body> <div id="root"> <h1>Contenteditable Test</h1> <div id="test" contenteditable="false"> <p>The quick brown fox jumps over the lazy dog.</p> </div> </div> </body> </html> The desired behaviour is: When you click on the test div, the content should become editable (and the style of the div should change accordingly - the test div gets a red outline). When you click outside the test div, the content should become not-editable (and the style of the div should change accordingly - the test div loses its red outline). When you click on the test div, its contenteditable attribute is set to 'true' and it becomes editable, as expected. When you click outside the test div, its contenteditable attribute is set to 'false', as expected, BUT its style does not change accordingly. I would expect it to change because the red outline style is predicated upon contenteditable being 'true' for the element, but the red outline remains even when contenteditable is no longer 'true'. By the way, I have tried 'false', false and 0, all to no avail. Obviously, I can force the style of the element when it is 'deselected', but that is a very ugly hack and will cause a headache if/when I want to change the contenteditable style in the future (I don't want to have to do it in several places - it should be possible to do it just in the CSS). Any ideas why this is happening? Hi all, I have a page built with asp.net that includes some "imagebutton"s within a form. These render as input tags with the type set to image. I ahve the onclick attribute set to run a custom javascript function and return false, so in the fully rendered page I get something like the following: Code: <input type="image" name="ctl00${cut}" tabindex="-1" title="Click to look up the details" src="images/load_details.png" onclick="LoadDetails(); return false;" style="border-width:0px;" /> This has worked fine for the few months the code has been in place and then just recently (within the last few days) it has stopped working for a single network user. They click on the link and instead of the function executing (and the AJAX loading details into the page) the form submits. This makes me think that the "return false" simply isn't executing. The user says that they haven't changed any settings or anything that may cause this issue... The browser being used throughout the company is IE8 under Windows XP. I have checked the version being used on their comptuer and it is 8.0.6001.18702, which is the same version as the one installed on my local machine... which is working fine. Another user has logged into the computer being used by the user with the issues and it works fine for the second user. Also, the user having the issues has logged into a different computer on the network and was still having the same problems. I think I've included all the details, but I'll happily provide any required information. Anyone have any ideas? hi peeps, this one might be confusing, if so i apologise! below is a cut down version of the script calling a function: Code: function updateStockRequest(thestatus,theform,thedate) { if(thestatus == 'locked') { if(checkStockRequested()) { if(confirm('Are you sure you want to send for processing?\nYou will not be able to add any more stock!')) { document.getElementById('status').value = 'locked'; document.forms[0].submit(); } } else { alert('You must request some stock first!'); } } } the following is the function being called: Code: function checkStockRequested() { //check to see if stockrequest has items added!!! xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var params = "?theuid=" + escape(document.getElementById('uid').value); var url="_check_stockrequest.php" url=url+params; ajaxedInner = ""; xmlHttp.open("GET",url,true); xmlHttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT"); xmlHttp.onreadystatechange=stateChanged; xmlHttp.send(null); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4){ if (xmlHttp.status == 200) { responsestring = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); alert(responsestring); if(responsestring == 'true') { return true; } else { return false; } } } } } in the testing the function is alerting 'true' but the calling function still fails and says you need to add stock. i must admit ive rarely used the return syntax so maybe im doing it wrong?!? ive tried many variants such as creating a variable and assigning it the string 'true' etc and then using if(checkStockRequested == 'true') but it still fails. help!!!!!!!!! Why is this happening? Code: var pattern = /^\s+|\s+$/g; var string = " spaces"; while(pattern.test(string)) { // -> true alert(pattern.test(string)); // -> false break; } alert(pattern.test(string)); // -> true Hi, In the attached code the outcome always defaults to the first test, even if the condition is false. How would I alter the syntax so that both condtions are evalauted? Code: var res = document.calc.num1.value*100/document.calc.num2.value; function cost1() { if (isNaN(res)) { document.calc.result1.value=0; } else { document.calc.result1.value=document.calc.num1.value*100/document.calc.num2.value; } } Thanks Iain hi guys, i need a javascript for my checkbox 1st: need to check the checkbox to go to next page or else stay at current page with an alert popout "Please check the checkbox" can some one help me please? This has stumped me for the last couple of hours and I was wondering if anyone else could shed some light... I have a page which loads some cookies, when taking the value from the cookie it defines whether a checkbox should be ticked or not. This works if the value of the cookie is true but not if the value is false and it ticks the box anyway. The code is.... Code: var widgetVal = loadCookie(widgetName); switch(i){ case 1: document.getElementById('calender_widget').checked = widgetVal; break; case 2: document.getElementById('calculator_widget').checked = widgetVal; break; case 3: document.getElementById('timetable_widget').checked = widgetVal; break; }; i is incremented each time in a for loop and a different cookie is loaded each time. As I said the code works if it set to true but not false however if I remove the variable and specify it as false it works. Thanks. Hi , I need your help in toggling the causes validation property of a link button depending upon the value selected from the radio button list...if i select "yes" from radio button then the linkbutton causes validation=true...if i select "no" from radio button then the linkbutton causes validation =false..help me out people hello, only just starting using javascript, so question may not make sense but il try anyway. if i group some javascript into a function that returns false; how could i carry that 'false' out of the function so it can be used outside the function. the example below shows the validate function checks for a condition then returns false if it is met. i want this false to then be passed out of the function to then throw an error in its containing function. (goal to prevent the submitting of a form) if (checBox =="1"){ validate(); } function proceed(); function validate() { if (chilD1.value >70) { alert("Please enter your Childs correct Age"); return false; chilD1.focus(); } } i dont want the proceed function to be called, so how can the other function prevent this. Now i realise that the validate function could be incorporated into the top level function but, my form will eventually be quite large with a multiplitude of fields so i need to know how i can call back to functions and use them as objects insteasd of repeating lots of code. Hope you can help thanks. Hello, I'm learning javascript and made this little program that takes the price, qty, adds tax and gives you a total. I put in an if statement so that if qty is 0, it becomes 1 then does the calcs. However, if I put in say price 5 and qty 2, qty is changing to false and it doesn't calc. Here it is: http://heresmary.com/test/Bought.html I am having trouble with some JavaScript that is supposed to add some Google Analytics tracking parameters to "cross-domain" links (used to auto append tracking info across multiple domains as a way of sharing the Google cookie info). I have my code kind of working at this point except the default event (the normal href link) is not stopping. Instead my new event (the link plus Google parameters) fires off and is immediately replaced by the default (no parameters) event. For links that open in a new window, two windows open, one the standard link and one with the intended parameters. I am using a return false; on each link type but it is not doing anything. Any ideas how I can stop the default event? Code: Code: //Last Updated 5/10/12 /*Regex list of on-site domains, pipe and backslash delimited. */ var wa_onsiteDomains = /mydomain\.com|my2nddomain\.com|my3rddomain\.com|javascript/i; /*Used to unobtrusivly add events to objects*/ function unobtrusiveAddEvent (element,event,fn) { var old = (element[event]) ? element[event] : function () {}; element[event] = function () {fn(); old();}; } function wa_crossDomainLink(i) { return function () { var thisLink = decodeURI(wa_links[i]); var thisLinkTarget = wa_links[i].target; if (typeof(_gaq) == "object") { if(thisLinkTarget == "_blank") { var wa_myTracker=_gat._getTrackerByName(); var wa_fullUrl = wa_myTracker._getLinkerUrl(thisLink); window.open(wa_fullUrl); return false; } else { _gaq.push(['_link', thisLink]); return false; } } }; } var wa_links = document.links; if ( wa_links ){ for(var i=0; i<wa_links.length; i++) { if( wa_links[i].href.match(wa_onsiteDomains) && !wa_links[i].href.match(location.hostname)){ unobtrusiveAddEvent( wa_links[i], 'onclick' , wa_crossDomainLink(i)); } } } Note, the code above resides in a separate js file and is called at the bottom of every page. Thanks! |