JavaScript - Checkbox Wont Recognise False
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. Similar Tutorialshi 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? Presently am using below code, and it is showing an error message says "Cannot call method "getCurrentWindow" of undefined (<Unknown source>#4) in <Unknown source> at line number 4" ========================================= function insertDataIntoHtmlEditorIE() { currentwindow = this.browserbot.getCurrentWindow(this); var iFrame = currentwindow.getElementById ('ctl00_MainContent_editor_ctl02_ctl00'); var iFrameBody; iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0]; iFrameBody.innerHTML = "xyz"; } ================================================ please help me out to resolve this issue.. *am calling this script in Selenium RC through Eclipse Hello! I'm rather new to the Javascript/jQuery world and I've been attempting to code a small game.. I've been attempting to get six images to evaluate either "Correct" or "Wrong" depending on which image they're dragged onto. apple, guava and pear(.png) should all evaluate correct when dropped onto sprite1, while pineapple, plum and purple should all evaluate correct when dropped onto sprite2. That said they should also evaluate wrong, when dropped onto the incorrect sprite. The problem I'm having is that they'll all either evaluate correct or wrong depending on whichever fruit is dropped onto a sprite first. It won't recognise when a fruit is dropped onto the incorrect sprite and I'm not sure what to add to make that happen? Diagram of problem: http://i.imgur.com/u9oH5Mo.png Code: <div id="answerBoxes"> <div id="target1" ondrop="drop(event)" ondragover="allowDrop(event)"> <img src="img/sprite1.png"/> </div> <div id="target2" ondrop="drop(event)" ondragover="allowDrop(event)"> <img src="img/sprite2.png"/> </div> </div> <!-- end of sprite's --> <div id="whatsWhatContent"> <div id="answers"> <div id="answer1Box" ondrop="drop(event)" ondragover="allowDrop(event)"> <img id="answer1" src="img/apple.png" draggable="true" ondragstart="drag(event)"/></div> <div id="answer2Box" ondrop="drop(event)" ondragover="allowDrop(event)"> <img id="answer2" src="img/guava.png" draggable="true" ondragstart="drag(event)"></div> <div id="answer3Box" ondrop="drop(event)" ondragover="allowDrop(event)"> <img id="answer3" src="img/pear.png" draggable="true" ondragstart="drag(event)"></div> <div id="answer4Box" ondrop="drop(event)" ondragover="allowDrop(event)"> <img id="answer4" src="img/pineapple.png" draggable="true" ondragstart="drag(event)"> <div id="answer5Box" ondrop="drop(event)" ondragover="allowDrop(event)"> <img id="answer5" src="img/plum.png" draggable="true" ondragstart="drag(event)"> <div id="answer6Box" ondrop="drop(event)" ondragover="allowDrop(event)"> <img id="answer6" src="img/purple.png" draggable="true" ondragstart="drag(event)"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script> <script> function allowDrop(ev){ ev.preventDefault(); } function drag(ev){ ev.dataTransfer.setData("content", ev.target.id); } function drop(ev){ ev.preventDefault(); var image = ev.dataTransfer.getData("content"); ev.target.appendChild(document.getElementById(image)); if($('#target1').find('#answer1').length == 1) { alert("CORRECT!"); } else if ($('#target2').find('#answer2').length == 1) { alert("Wrong."); } else { alert("Wrong!"); } } Hi Guys, im using chrome and ff and it worked fine till i tested on ie7 and the form just wont send on ie7. it gives me a validation error msg "SOME VALUES ARE NOT ACCEPTABLE" when i try to submit. ive tried so many things and i cant figure out why ie7 wont send upon submit like ff does, code seems to be fine, pls see validation coding line 7 - 32 , any jsGURU advice will be much appreciated! Code: <?php defined('_JEXEC') or die('Restricted access'); ?> <?php JHTML::_('behavior.formvalidation'); ?> <script language="javascript" type="text/javascript"> function submitbutton(pressbutton) { var form = document.adminForm; if (pressbutton == 'cancel') { submitform( pressbutton ); return; } // do field validation if (document.getElementById('jformfirstname').value == ""){ alert( "<?php echo JText::_( 'Firstname is missing.', true ); ?>" ); } else if (document.getElementById('jformsurname').value == ""){ alert( "<?php echo JText::_( 'Surname is missing.', true ); ?>" ); } else if (document.getElementById('jformemail').value == ""){ alert( "<?php echo JText::_( 'Email is missing.', true ); ?>" ); } else if (document.getElementById('jformphone1').value == ""){ alert( "<?php echo JText::_( 'Phone1 is missing.', true ); ?>" ); } else { if (document.formvalidator.isValid(form)) { submitform( pressbutton ); } else { alert("<?php echo JText::_( 'SOME VALUES ARE NOT ACCEPTABLE.', true ); ?>"); } } } </script> <?php if ($this->courseid){ ?> <?php if ( $this->params->def( 'show_page_title', 1 ) ) : ?> <div class="componentheading<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> <?php echo $this->courseDetails->title; ?> </div> <?php endif; ?> <h3>Course Details</h3> <table cellSpacing=0 cellPadding=5 width="90%" border=0> <tr> <td width="20%"><?php echo JText::_( 'Course Title' ); ?>:</td> <td width="30%"><?php echo $this->courseDetails->title;?></td> <td width="20%"><?php echo JText::_( 'Code' ); ?>:</td> <td width="30%"><?php echo $this->courseDetails->code;?></td> </tr> <tr> <td><?php echo JText::_( 'Price' ); ?>:</td> <td><?php echo (number_format($this->courseDetails->price,2));?></td> <td><?php echo JText::_( 'No. of Days' ); ?>:</td> <td><?php echo $this->courseDetails->capacity;?></td> </tr> <tr> <?php if ($_GET['hide'] != 1 ) { ?> <td><?php echo JText::_( 'Location' ); ?>:</td> <td><?php echo $this->courseDetails->course_location;?></td> <?php } else { echo "<td> </td>"; echo "<td> </td>"; } ?> </tr> <tr> <?php if ($_GET['hide'] != 1 ) { ?> <td><?php echo JText::_( 'Start Date' ); ?>:</td> <td><?php echo Date('d-M-y', strtotime($this->courseDetails->start_date));?></td> <?php } else { echo "<td> </td>"; echo "<td> </td>"; } ?> </tr> </table> <?php } ?> <?php if ( $this->params->def( 'show_course_sessions', 1 ) && ($this->courseid) ) : ?> <h3>Sessions</h3> <table cellSpacing=0 cellPadding=5 width="90%" border=0> <tr> <td width="20%" align="center" height="20" class="sectiontableheader<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> <?php echo JText::_('Day'); ?> </td> <td width="20%" align="center" height="20" class="sectiontableheader<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> <?php echo JText::_('Start Time'); ?> </td> <td width="20%" align="center" height="20" class="sectiontableheader<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> <?php echo JText::_('Finish Time'); ?> </td> <td width="10%" align="center" height="20" class="sectiontableheader<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> <?php echo JText::_('Duration'); ?> </td> <td width="30%" align="center" height="20" class="sectiontableheader<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> <?php echo JText::_('Location'); ?> </td> </tr> <?php $k = 0; $n=count( $this->course_sessions ); if ($n > 0){ for ($i=0, $n; $i < $n; $i++) { $row = &$this->course_sessions[$i]; ?> <tr> <td align="center"> <?php echo $row->session_day;?> </td> <td align="center"> <?php echo date('H:i', strtotime($row->start_time));?> </td> <td align="center"> <?php echo date('H:i', strtotime($row->finish_time));?> </td> <td align="center"> <?php echo $row->duration;?> </td> <td align="center"> <?php echo $row->session_location;?> </td> </tr> <?php $k = 1 - $k; } } else { ?> <tr> <td colspan="5"><? echo JText::_( 'There are no sessions for this course' );?></td></tr><?php } ?> </table> <?php endif; ?> <form action="<?php echo $this->action ?>" method="post" name="adminForm" id="adminForm" class="form-validate"> <?php if ( $this->params->def( 'show_page_title', 1 ) ) : ?> <div class="componentheading<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> <?php echo $this->escape($this->params->get('page_title')); ?> </div> <?php endif; ?> <table cellpadding="4" cellspacing="1" border="0" width="100%"> <tr> <td width="15%"> <label for="jformcourseid"> <?php echo JText::_( 'Course' ); ?>: </label> </td> <td> <?php echo $this->lists['courseid'];?>* </td> </tr> <?php if ($_GET['hide'] == 1 ) { ?> <tr> <td valign="top"> <label for="jformcity"> <?php echo JText::_( 'I want to attend this course here' ); ?>: </label> </td> <td width="80%"> <select class="required" type="text" id="jformcountry" name="jform[country]" value="<?php echo $this->escape($this->booking->country);?>" />* <option>Choose your Location</option> <option>Melbourne</option> <option>Sydney</option> <option>Auckland</option> </select> </td> </tr> <?php } ?> <tr> <td valign="top"> <label for="jformfirstname"> <?php echo JText::_( 'Firstname' ); ?>: </label> </td> <td width="80%"> <input class="required" type="text" id="jformfirstname" name="jform[firstname]" size="50" maxlength="250" value="<?php echo $this->escape($this->booking->firstname);?>" />* </td> </tr> <tr> <td valign="top"> <label for="jformsurname"> <?php echo JText::_( 'Surname' ); ?>: </label> </td> <td valign="top"> <input class="required" type="text" id="jformsurname" name="jform[surname]" size="50" maxlength="250" value="<?php echo $this->escape($this->booking->surname);?>" />* </td> </tr> <?php if($this->userid > 0) { ?> <tr> <td valign="top"> <label for="jformusername"> <?php echo JText::_( 'Username' ); ?>: </label> </td> <td width="80%"> <input class="required" type="text" id="jformusername" name="jform[username]" size="50" maxlength="100" value="<?php echo $this->escape($this->username);?>" READONLY/>* </td> </tr> <?php } ?> <tr> <td valign="top"> <label for="jformdepartment"> <?php echo JText::_( 'Company' ); ?>: </label> </td> <td width="80%"> <input class="inputbox" type="text" id="jformdepartment" name="jform[department]" size="50" maxlength="30" value="<?php echo $this->escape($this->booking->department);?>" /> </td> </tr> <tr> <td valign="top"> <label for="jformemail"> <?php echo JText::_( 'Email' ); ?>: </label> </td> <td width="80%"> <input class="validate-email" type="text" id="jformemail" name="jform[email]" size="50" maxlength="100" value="<?php echo $this->escape($this->email);?>"/>* </td> </tr> <tr> <td valign="top"> <label for="jformphone1"> <?php echo JText::_( 'Phone Number' ); ?>: </label> </td> <td width="80%"> <input class="required" type="text" id="jformphone1" name="jform[phone1]" size="50" maxlength="20" value="<?php echo $this->escape($this->booking->phone1);?>" />* </td> </tr> <tr> <td valign="top"> <label for="jformcity"> <?php echo JText::_( 'Locations' ); ?>: </label> </td> <td width="80%"> <select type="text" id="jformcity" name="jform[city]" value="<?php echo $this->escape($this->booking->city);?>" /> <option>Choose your Location</option> <option>Melbourne</option> <option>Sydney</option> <option>Auckland</option> </select> </td> </tr> <tr> <td valign="top"> <label for="jforminstitution"> <?php echo JText::_( 'Referral Source' ); ?>: </label> </td> <td width="80%"> <select type="text" id="jforminstitution" name="jform[institution]" value="<?php echo $this->escape($this->booking->institution);?>" /> <option>How did you find out about us?</option> <option>Search Engine</option> <option>Friends</option> <option>Others</option> </select> </td> </tr> <tr> <td valign="top"> <label for="jformdescription"> <?php echo JText::_( 'Comments' ); ?>: </label> </td> <td> <textarea class="inputbox" cols="47" rows="6" id="jformdescription" name="jform[description]"><?php echo $this->escape( $this->booking->description);?></textarea> </td> </tr> </table> <div> <button type="button" class="button validate" onclick="submitbutton('save')"> <?php echo JText::_('Save') ?> </button> <button type="button" onclick="submitbutton('cancel')"> <?php echo JText::_('Cancel') ?> </button> </div> <input type="hidden" name="jform[id]" value="<?php echo $this->booking->id; ?>" /> <input type="hidden" name="jform[ordering]" value="<?php echo $this->booking->ordering; ?>" /> <input type="hidden" name="jform[approved]" value="<?php echo $this->booking->approved; ?>" /> <input type="hidden" name="jform[userid]" value="<?php echo $this->userid; ?>" /> <input type="hidden" name="option" value="com_courseman" /> <input type="hidden" name="controller" value="booking" /> <input type="hidden" name="task" value="" /> <?php echo JHTML::_( 'form.token' ); ?> </form> </br> Fields marked with an asterisk (*) are required. </br> </br> So here's what i want to do: i have 2 checkboxes, when Checkbox A is checked, i want to automatically check the checkbox B. When A is unchecked, then uncheck B how can i do that? thanks a lot ! 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 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? 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 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"; } } 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; } } 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. 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, 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 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!!!!!!!!! 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 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 Lets say I have a MySQL value of 4... and I have a HTML INPUT field.. Is there a way to make it so that if a client tries to submit a value higher than 4, then they will be returned a message? Something like: Code: <SCRIPT type="text/javascript"> function validateForm() { if (document.forms["form"]["quantity"].value== (+$row['quantity']) { alert ("Cannot submit because the quantity specified is not available."); return false; } } </SCRIPT> <INPUT name="quantity" onsubmit="return validateForm()> |