JavaScript - Problem With .getday() Function Not Returning The Correct Day.
I find it odd that this function is returning the day as 1, when it is clearly the 28th.
when I run the code the answer I get looks like this: 1-Feb-2011 9:27 Code: function getDateTime(when) { var theDate = new Date(); var day = theDate.getDay(); var month = theDate.getMonth(); var year = theDate.getFullYear(); var myTimeArr = theDate.toTimeString().split(":"); var monthNumber = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") when.value = day + "-" + monthNumber[month] + "-" + year + " " + myTimeArr[0] + ":" + myTimeArr[1]; any advice? Similar TutorialsI am using the following script to have a calander displayed in my form. It displays a calender on which a user can select a date. If the date is a friday, something else should happen in the form than when selecting other days (see final 15 lines, no need to be specific). The problem is that the code only works for months with 30 days in it. E.g. The september month works fine, when a friday is selected (javascript:setCalendarControlDate(2009,9,25)) the correct changes occur. For the October month (31 days) the same changes that occur correct in september occur in october when selecting thursday, but these should be when selecting friday instead! For November (30 days) everything works fine again, but then for December (31 days) the changes occur again at thursday instead of friday For February (2010) I need to select sunday to get the needed changes. Like I said, I think it has something to do with the amount of days in a month. Since the code works fine on months with 30 days, but not on months with other amounts of days. Can anyone tell me what's wrong in the code? Code: function positionInfo(object) { var p_elm = object; this.getElementLeft = getElementLeft; function getElementLeft() { var x = 0; var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } while (elm != null) { x+= elm.offsetLeft; elm = elm.offsetParent; } return parseInt(x); } this.getElementWidth = getElementWidth; function getElementWidth() { var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } return parseInt(elm.offsetWidth); } this.getElementRight = getElementRight; function getElementRight() { return getElementLeft(p_elm) + getElementWidth(p_elm); } this.getElementTop = getElementTop; function getElementTop() { var y = 0; var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } while (elm != null) { y+= elm.offsetTop; elm = elm.offsetParent; } return parseInt(y); } this.getElementHeight = getElementHeight; function getElementHeight() { var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } return parseInt(elm.offsetHeight); } this.getElementBottom = getElementBottom; function getElementBottom() { return getElementTop(p_elm) + getElementHeight(p_elm); } } function CalendarControl() { var calendarId = 'CalendarControl'; var currentYear = 0; var currentMonth = 0; var currentDay = 0; var selectedYear = 0; var selectedMonth = 0; var selectedDay = 0; var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; var dateField = null; function getProperty(p_property) { var p_elm = calendarId; var elm = null; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } if (elm != null) { if(elm.style) { elm = elm.style; if(elm[p_property]) { return elm[p_property]; } else { return null; } } else { return null; } } } function setElementProperty(p_property, p_value, p_elmId) { var p_elm = p_elmId; var elm = null; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } if((elm != null) && (elm.style != null)) { elm = elm.style; elm[ p_property ] = p_value; } } function setProperty(p_property, p_value) { setElementProperty(p_property, p_value, calendarId); } function getDaysInMonth(year, month) { return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1]; } function getDayOfWeek(year, month, day) { var date = new Date(year,month-1,day) var DayOfWeek = date.getDay(); if(DayOfWeek == 0) DayOfWeek = 6; else DayOfWeek--; return DayOfWeek; } this.setDate = setDate; function setDate(year, month, day) { if (dateField) { if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } var dateString = day+"-"+month+"-"+year; dateField.value = dateString; hide(); } return; } this.changeMonth = changeMonth; function changeMonth(change) { currentMonth += change; currentDay = 0; if(currentMonth > 12) { currentMonth = 1; currentYear++; } else if(currentMonth < 1) { currentMonth = 12; currentYear--; } calendar = document.getElementById(calendarId); calendar.innerHTML = calendarDrawTable(); } function getCurrentYear() { var year = new Date().getYear(); if(year < 1900) year += 1900; return year; } function getCurrentMonth() { return new Date().getMonth() + 1; } function getCurrentDay() { return new Date().getDate(); } function calendarDrawTable() { var dayOfMonth = 1; var validDay = 0; var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth); var daysInMonth = getDaysInMonth(currentYear, currentMonth); var css_class = null; //CSS class for each day var table = "<table cellspacing='0' cellpadding='0' border='0'>"; table = table + "<tr class='header'>"; table = table + " <td colspan='2' class='previous'><a href='javascript:changeCalendarControlMonth(-1);'><</a></td>"; table = table + " <td colspan='3' class='caltitle'>" + months[currentMonth-1] + "<br>" + currentYear + "</td>"; table = table + " <td colspan='2' class='next'> <a href='javascript:changeCalendarControlMonth(1);'>></a></td>"; table = table + "</tr>"; table = table + "<tr><th>Mon.</th><th>Tues.</th><th>Wed.</th><th>Thurs.</th><th>Fri.</th><th>Sat.</th><th>Sun.</th></tr>"; for(var week=0; week < 6; week++) { table = table + "<tr>"; for(var dayOfWeek=0; dayOfWeek < 7; dayOfWeek++) { if(week == 0 && startDayOfWeek == dayOfWeek) { validDay = 1; } else if (validDay == 1 && dayOfMonth > daysInMonth) { validDay = 0; } if(validDay) { if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) { css_class = 'current'; } else if (dayOfMonth == getCurrentDay() && currentYear == getCurrentYear() && currentMonth == getCurrentMonth()) { css_class = 'today'; } else if ((dayOfWeek == 5 || dayOfWeek == 6) && (dayOfMonth > getCurrentDay() || currentMonth > getCurrentMonth() || currentYear > getCurrentYear())) { css_class = 'weekend'; } else { css_class = 'weekday'; } if (((dayOfMonth < getCurrentDay() && currentMonth <= getCurrentMonth()) && currentYear <= getCurrentYear()) || currentYear < getCurrentYear()) { table = table + "<td><span class='dayinpast'>"+dayOfMonth+"</span></td>"; } else { table = table + "<td><a class='"+css_class+"' href=\"javascript:setCalendarControlDate("+currentYear+","+currentMonth+","+dayOfMonth+")\">"+dayOfMonth+"</a></td>"; } dayOfMonth++; } else { table = table + "<td class='empty'> </td>"; } } table = table + "</tr>"; } table = table + "<tr class='header'><th colspan='7' style='padding: 3px; text-align:center;'><a href='javascript:hideCalendarControl();'>Close</a></td></tr>"; table = table + "</table>"; return table; } this.show = show; function show(field) { if (dateField == field) { hide(); return; } else { dateField = field; } if(dateField) { try { var dateString = new String(dateField.value); var dateParts = dateString.split("-"); selectedDay = parseInt(dateParts[0],10); selectedMonth = parseInt(dateParts[1],10); selectedYear = parseInt(dateParts[2],10); } catch(e) {} } if (!(selectedYear && selectedMonth && selectedDay)) { selectedMonth = getCurrentMonth(); selectedDay = getCurrentDay(); selectedYear = getCurrentYear(); } currentMonth = selectedMonth; currentDay = selectedDay; currentYear = selectedYear; if(document.getElementById) { calendar = document.getElementById(calendarId); calendar.innerHTML = calendarDrawTable(currentYear, currentMonth); setElementProperty('display', 'block', 'CalendarControlIFrame'); setProperty('display', 'block'); var fieldPos = new positionInfo(dateField); var calendarPos = new positionInfo(calendarId); var x = fieldPos.getElementLeft() - document.getElementById('table_left').scrollLeft; var y = fieldPos.getElementBottom() - document.getElementById('table_left').scrollTop; var w = calendarPos.getElementWidth(); var h = calendarPos.getElementHeight(); var ch = document.getElementById('table_left').style.height; ch = parseInt(ch.substring(0, ch.length-2)) + 143; var cw = document.getElementById('table_left').style.width; cw = parseInt(cw.substring(0, cw.length-2)) + 150; if(y+h > ch) y = ch - h; if(x+w > cw) x = cw - w; setProperty('left', x + "px"); setProperty('top', y + "px"); setElementProperty('left', x + "px", 'CalendarControlIFrame'); setElementProperty('top', y + "px", 'CalendarControlIFrame'); setElementProperty('width', w + "px", 'CalendarControlIFrame'); setElementProperty('height', h + "px", 'CalendarControlIFrame'); } } this.hide = hide; function hide() { if(dateField) { setProperty('display', 'none'); setElementProperty('display', 'none', 'CalendarControlIFrame'); dateField = null; } getSelectedDate('cd_pickup_date') } } var calendarControl = new CalendarControl(); function showCalendarControl(textField) { calendarControl.show(textField); } function hideCalendarControl() { calendarControl.hide(); } function setCalendarControlDate(year, month, day) { calendarControl.setDate(year, month, day); } function changeCalendarControlMonth(change) { calendarControl.changeMonth(change); } document.write("<div id='CalendarControl'></div>"); function getSelectedDate(value) { var selectedDate = document.getElementById('cd_pickup_date').value; var selectedDateArray = selectedDate.split("-"); var convertedDate = new Date(selectedDateArray[2],selectedDateArray[1],selectedDateArray[0]); var selectedDay = convertedDate.getDay(); var weekDay = new Array("Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"); if(weekDay[selectedDay] == "Friday") { document.collectionform.cd_saturday[0].checked = true; document.collectionform.cd_saturday[0].disabled = false; document.collectionform.cd_saturday[1].disabled = true; getAlternateAddress('Yes'); } else { document.collectionform.cd_saturday[1].checked = true; document.collectionform.cd_saturday[1].disabled = false; document.collectionform.cd_saturday[0].disabled = true; getAlternateAddress('No'); } } Hello, another noob question for you: I have a function that requires the ability to count the number of entries in an array. I'm using the following to call my function inside an input tag: Code: onblur="javascript:check(this.name, this.value, 1, 10);" which for example is calling check('field1', 'foobar', 1, 10) Here is the javascript: Code: function check(name, value, min, max){ var errors=new Array(); if(value.length < min || value.length > max){ //checking against min/max length of value errors[name] = "Text field must not be blank."; errors["blabla"] = "array value 2"; //added for testing purposes alert(name+" : "+value); //returns "field1 : foobar" } alert(errors.length); // returns "0" } And when errors.length is alerted, it outputs 0. I can only figure that there is an issue when using custom named keys in an array, since this works when I use only integers, however, I have the need to use a custom key index as shown. Any ideas? Hey guys..... My skill level on JavaScript is only intermediate so maybe this is really obvious.... but it's driving me nuts & I can't work it out. Heres some example code.. Code: function createAJAXobject() { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { /* alert("Cannot create object in IE."); */} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { /* alert("Cannot create object in IE."); */} try { return new XMLHttpRequest(); } catch(e) { /* alert("Cannot create object in Mozilla."); */} alert("XMLHttpRequest is not supported."); return null; } function ajaxRequest(url) { // Create AJAX object var myAJAX = createAJAXobject(); // Retrieve data myAJAX.open("GET",url,true); myAJAX.onreadystatechange = function() { // Was it a success? if (myAJAX.readyState < 4) { return false; } // Set results var res = myAJAX.responseText; /* Returns results */ if (res != '') { return res; // Correctly enters this part via testing // Output of the variable 'res' here outputs correct text } else { return false; } } myAJAX.send(null); } function searchCats(text) { // Set URL for ajax request var url = 'search_cats.php?search_text='+text; // Set up element we're modifying var results = document.getElementById('cat_list'); // Send the request var ajaxResponse = ajaxRequest(url); alert(ajaxResponse); // = undefined } I have included comments in the above explaining my problems..... the data is correct when I use alert() just before I return it, but when I use alert inside the function that calls it I get "undefined" & the error in FireFox says "ajaxResponse" is undefined. Please please someone help! I am trying to make a page that shows a daily special for a *fake* pizza place. I want it to detect the day it is, and write the special within the document as an H1 heading or something like that. For testing I have it setup to do an Alert, but it alerts me of the monday special today which is correct, but if I change my system time to another day it doesn't work. Does it work like that or is there a better way to test it? Here is the code, there is a <body onload="getToday()"> in place Code: function getToday() { var d = new Date(); var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; if (weekday[d.getDay()] = 0) { alert("Buy one Pizza get a second for only $5"); } else if (weekday[d.getDay()] = 1) { alert("Order of Breadsticks for $1"); } else if (weekday[d.getDay()] = 2) { alert("Order of Cinnamon Sticks for $1"); } else if (weekday[d.getDay()] = 3) { alert("Free Two Liter with Pizza Order"); } else if (weekday[d.getDay()] = 4) { alert("Order of Hot Wings for $1"); } else if (weekday[d.getDay()] = 5) { alert("Orders of Breadsticks, Cinnamon Sticks, and 2 liter for $3 with"); } else if (weekday[d.getDay()] = 6) { alert("Breadsticks and a two liter for $1"); } } </script> Hi everyone, I have a hunch that my function is not returning the string value. Below runs some information about the code: getvalues_2() - A function that recognizes the value of the string selected by the user from the drop down list and sends it to a variable. Variable name is 'groom_profession' here. Based on the value (text) returned, it assigns a particular number to the variable 'profession' in this case. But, I have been noticing that irrespective of the value chosen from the drop down list, the variable 'profession' is assigned a default value from the switch case statement. I know the variable (textval_2) is able to store the correct value from the drop down list with the help of an alert command. But, it fails while returning the value. I even tried initializing the string in the function body but to no avail. What could be wrong here? Following is the code for one of the drop-down lists: Code: <b> Groom's current Profession </b> <FORM NAME="Profession"> <SELECT NAME="Groomprofession" onchange = "getvalues_2()"> <OPTION VALUE="c1">Select </OPTION> <OPTION VALUE="c2">Doctor </OPTION> <OPTION VALUE="c3">Engineer </OPTION> <OPTION VALUE="c4">Lawyer </OPTION> <OPTION VALUE="c5">CA </OPTION> <OPTION VALUE="c6">IAS </OPTION> <OPTION VALUE="c7">Engineer + MBA </OPTION> <OPTION VALUE="c8">Family Business </OPTION> <OPTION VALUE="c9">None of the above </OPTION> </SELECT> </FORM> Following is the code for function getvalues_2() declaration: Code: <script type = "text/javascript"> function getvalues_2() { var val_2 = document.Profession.Groomprofession.value; var si_2 = document.Profession.Groomprofession.selectedIndex; if (si_2 != 0) { var textval_2 = " "; textval_2 = document.Profession.Groomprofession.options[si_2].text; //alert (val_2); // for testing //alert (textval_2); // for testing return (textval_2); } } </script> Following is the code for the switch case statement: Code: <script type="text/javascript"> var profession; groom_profession = getvalues_2(); switch(groom_profession) { case "Engineer" : profession = 1.8; break; case "Doctor" : profession = 1.9; break; case "Lawyer" : profession = 1.65; break; case "CA" : profession = 1.7; break; case "IAS" : profession = 2.0; break; case "Family Business" : profession = 1.5; break; case "Engineer + MBA" : profession = 1.95; break; case "None of the above" : profession = 1.95; break; default: profession = 0.6; } </script> The website has a total of 11 drop-down lists (so 11 functions like getvalues, and 11 switch case statements. I thought if I could get one to work, the others might follow suit too). I would be really grateful if someone could look into my problem and suggest where I am going wrong. Thanks a lot! I have a function where in I call another function that assigns a value to a var. e.g. Code: function setVar{ var thisVar = 'hello'; return thisVar; } function callFuncSetVar { var newVar = setVar(); alert(newVar); } For some reason my code below is returning 'undefined'. But when I place an alert(); before the 'return' it shows the correct value. However when I place an alert(); to show the var that is set to what the function returns it says 'undefined'. Firebug throws no errors. I am using a little bit of jQuery. Scenario: Client Side : Simple functions that have events tied to different elements. Each time an event is triggered the function begins an Ajax call to an external server side page filled with JS functions. Server Side : Our client side AJAX call sends the name of the function we want to call out on this file. Once called and performed, it returns DOM edits that could be fired once our client side page receives the data back from Ajax. I know that data being returned from Ajax is always a string. But would it be possible? I mean could the server side file send out commands or rather DOM edits that the client side could pick up on and perform? I am almost 100% certain the answer is no due to JS needing to be cached in the browser and what not, but I figured I would ask the experts anyways. BTW: objective is to move sensitive core JS functions to prevent online application theft... without Flex or Air. I am wondering how can I return the variable senttext from the function below? I have declared it and when I alert(senttext) below it appears as I want it but I need to return it and pass it to another function. When I change alert() to return the variable becomes undefined??? var senttext; function getData() { if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open('GET',"http://www.site6.certcoordering1.com/Download/recall.txt" ); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200) { senttext ='<table style="border:thin black solid"><tr><td><h2>Recent</h2></td><td><h2>Recalls</h2></td><td></td><td></td></tr>' ; var ad2 = req.responseText.split("\n"); for(i=0; i<ad2.length-1; i++) { // now split by comma var ad3 = ad2[i].split(","); senttext += '<tr><td><p>'+ad3[0]+'</p></td><td> <a href="http://www.site6.certcoordering1.com/Download/'+ad3[2]+' rel="nofollow" target="_blank">'+ad3[1] +'</a></td><td></td></tr>' } senttext += '</table>' ; alert(senttext); // I need to return senttext, not alert! When I send it it becomes undefined? } else { alert('File did not load correctly.'); } } } req.send(""); } Whats wrong with the code below? I'm trying to get the email service provider name. Code: <html> <head> <script type="text/javascript"> function GetProvider { var fullemail = openinviter.email_box.value; var afterat = fullemail.split("@"); var Provider = afterat[1].split("."); var showit = Provider[0]; openinviter.provider_box.value=showit; } </script> </head> <body> <form action="" method="post" name="openinviter"> <input type="text" name="email_box" onchange="GetProvider()" /> <input type="text" name="provider_box" value=""> </form> </body> </html> Thanks alot! This code is finally working, but for some reason no matter which button i click on, it is always returning "9". It should be firing the alert(x), where x is the x index value for that particular addEventListener Code: .addEventListener('click', function (e) {alert(x);}, Code: <html> <script type="text/javascript"> document.addEventListener('DOMContentLoaded', DOMLoadedEventFunction, false); function DOMLoadedEventFunction () { for(var x = 0; x < 9; x++) { document.getElementById('btn' + x).addEventListener('click', function (e) {alert(x);}, false); } } </script> <body> <input type="button" id="btn0" value="1"> <input type="button" id="btn1" value="2"> <input type="button" id="btn2" value="3"> <input type="button" id="btn3" value="4"> <input type="button" id="btn4" value="5"> <input type="button" id="btn5" value="6"> <input type="button" id="btn6" value="7"> <input type="button" id="btn7" value="8"> <input type="button" id="btn8" value="9"> <input type="button" id="btn9" value="10"> </body> </html> This is just some sample code that i will later turn into an HTML5 File Manager Hi, I have the below function and I keep getting the error Lid is not defined. Code: <script type="text/javascript"> function loadTips(file,ID,File,id){ alert(file); alert(ID); alert(File); alert(id); loadXMLDoc(file,ID); var l=setTimeout("loadXMLDocRefresh(File,id)",10000); } </script> My trigger button is: <input type="button" class="button3" value="Tips" onclick="loadTips('getTees.php','txtHintTees','getLees.php','txtHintLees')" /> So my alert Lid comes up with txtHintLees, so it is working up until the alert. Which leads me to believe that maybe it doesn't like being wrapped in "", without "" though firebug halts the process. I tried wrapping it in {} e.g. {loadXMLDocRefresh(File,id)} but that wasn't liked either. I'll stop my list of things I tried that don't work now. But does anyone have any ideas? A while back, Old Pedant wrote a nifty function which changes the class of different sets of <p> elements, in order to change the content and style of their css ':afters'. You can see it in action here: welcome > consult > ready ? > make line one > etc: the ':afters' are the small red markers which appear in the middle of the red lines. I'm now writing functions for "back" links which will return the page to its original state. I've managed to do this for most elements (change display, colour, etc): however, these ':afters' are proving a problem. The css for the original ':afters' Code: .hex p:after { position:relative; top:0.74em; left:-2.10em; z-index:-1; font-size:0.50em; content:":"; visibility:hidden; } The logic of applying elaborate css, and then hiding the result is this: the css alters the line-height of the p element, so a dummy version is to applied at the outset, before the specific versions are activated. The css for the changed ':afters' Code: p.xV1:after, p.xV2:after, p.xV3:after, p.xV4:after, p.xV5:after, p.xV6:after { color:#f03; visibility:visible; content:"x"; } p.oV1:after, p.oV2:after, p.oV3:after, p.oV4:after, p.oV5:after, p.oV6:after { color:#f03; visibility:visible; content:"O"; } What needs to happen is for all of these p classes to be returned to the css '.hex p:after' . I think the function might look something like Code: function returnAfters(){ for (i=0; i<elP.length; i++) { if (elP.item(i).className.charAt(1) == "V") { elP.item(i).className = "hex p";} } The original function, altho I don't think it's needed to solve this, can be found here, at line 295. Meanwhile, one other problem area involves a jQuery function, so I'll post elsewhere. Cheers! Here is a clip of code from a script project im working on. Now my document.getElementsByTagName is returning a "undefined" value. Can anyone tell me whats wrong with my code? Code: <a href="http://www.anotherrandomsite.com" style="text-decoration: none; color: #EDDBAF; font-size: 16px;"> <center style="margin-left: 10px; margin-right: 10px;"> <font style="color: #EDDBAF; font-size: 16px;" id="title"></font> </center> </a> <li id="name"><a http="http://www.randomsite.com" style="color: blue;">John Doe</a></li> <script type="text/javascript"> var pname = document.getElementById('name').getElementsByTagName('a'); //now if i remove the ".getElementsByTagName('a')" it will actually work, but it also includes the <a> tag thats within the <li> tag, which i dont want. document.getElementById('title').innerHTML=pname.innerHTML; </script> <p> <script type="text/javascript">// <![CDATA[ var metrics = { "mm" : 1, "cm" : 10, "m" : 1000, "inch" : 25.4, "foot" : 304.8 }; function convert(num, dec){ var val = document.getElementById("fromVal").value; if(isNaN(val)){ return } function roundNumber(num, dec) { var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec); return result; } document.getElementById("toVal").value = val * metrics[document.getElementById("fromSystem").value]/ metrics[document.getElementById("toSystem").value]; } var interval = null; function watchChanges(){ interval == null ? setInterval("convert()", 500) : clearInterval(interval); } // ]]></script> </p> <table> <tbody> <tr> <td><input id="fromVal" style="width: 100px;" onfocus="watchChanges()" onblur="watchChanges()" type="text" /><select id="fromSystem" onchange="convert()"> <option value="mm">millimeters</option> <option selected="selected" value="cm">centimeters</option> <option value="m">meters</option> <option value="foot">feet</option> <option value="inch">inches</option> </select></td> </tr> <tr> <td colspan="1" align="center">=</td> </tr> <tr> <td><input id="toVal" style="width: 100px;" type="text" disabled="disabled" /><select id="toSystem" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option value="m">meters</option> <option selected="selected" value="foot">feet</option> <option value="inch">inches</option> </select></td> Hello, I'm working on my little grabber and now I want to try something in javascript without success, so here my javascript code: PHP Code: //begin ajax grabber function validateGrabber(b_on_submit){ if(document.grabber.keywords.value == '' || document.grabber.keywords.value == 'search'){ alert('You did not enter a search term. Please try again.'); if(b_on_submit == 'true') return false; } else{ document.grabber.btn.submit(); } } function grabber(inputGrabber) { if(inputGrabber.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else if(inputGrabber.length > 2) { $.post(MELODYURL2+'/ajax_grabber.php', {queryString: ""+inputGrabber+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // end ajax grabber and that's my template code: PHP Code: <form action="{$smarty.const._URL}/search.php" method="get" id="search" name="grabber" onsubmit="return validateGrabber('true');"> <input name="keywords" type="text" value="" class="search_keywords" id="inputGrabber" {if $smarty.const._SEARCHSUGGEST == 1}onkeyup="grabber(this.value);" onblur="fill();" autocomplete="off"{/if} /> <input name="btn" value="{$lang.submit_search}" type="submit" class="search_bttn" /> <div class="suggestionsBox" id="suggestions" style="display: none;"> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> </form> the first function doesn't show the alert and the second doesn't work at all... Code: <select class="drop" name="pet Display" id="drop" onChange="if(this.options[this.selectedIndex].value=='a') {document.getElementById('myFieldSet').style.visibility='visible'} else{document.getElementById('myFieldSet').style.visibility='hidden'}if(this.options[this.selectedIndex].value=='b') {document.getElementById('myFieldSet1').style.visibility='visible'} else{document.getElementById('myFieldSet1').style.visibility='hidden'}if(this.options[this.selectedIndex].value=='c') {document.getElementById('myFieldSet2').style.visibility='visible'} else{document.getElementById('myFieldSet2').style.visibility='hidden'}"> i need to fix this function or a different (external is better )with the same results thanxz Hi, In ASP.NET intranet web page have user input. Have 5 check boxes with two attending text boxes for each. The default value for the text boxes is zero and the text boxes are disabled for input. When the user checks a check box the two corresponding text boxes become enabled for input. Have two command buttons - Submit for database posting and Cancel. I set the Cancel button with a js window.confirm, uncheck the check boxes, and reset any input values in the text boxes back to zero. When I tested the code the checked check boxes were unchecked and the first text box holding user input was reset to zero value. However, the other text boxes containing user input values were not reset to zero. I altered the sequence of the code - for example - list the check box then its text boxes and so on. I tried listing the text boxes first then the check boxes. These did not resolve the problem - I was thinking linear execution of the code. Any suggestions to rememdy this? This is the js function: function Empty() { var res=window.confirm("Please confirm cancellation-your input will be cleared"); if(res==true) { document.getElementById("chkDVTT").value=""; document.getElementById("chkLM").value=""; document.getElementById("chkVMB").value=""; document.getElementById("chkVEB").value=""; document.getElementById("chkVUB").value=""; document.getElementById("txtDVTTRegHrs").value="0"; document.getElementById("txtDVTTOTHrs").value="0"; document.getElementById("txtBRLMRegHrs").value="0"; document.getElementById("txtBrLMOTHrs").value="0"; document.getElementById("txtVMBRegHrs").value="0"; document.getElementById("txtVMBOTHrs").value="0"; document.getElementById("txtVEBRegHrs").value="0"; document.getElementById("txtVEBOTHrs").value="0"; document.getElementById("txtVUBRegHrs").value="0"; document.getElementById("txtVUBOTHrs").value="0"; } } Thanks, John Hi guys, I'm a bit new to all this javascript and of course I have a problem.. I have searched all the forums and none have helped me fix this problem.. js file: function buildTable (prodNum){ moo = document.GetElementById('showProd').insertRow(0); /*some crap code*/ } html code: <table id = "showProd" border ="3"></table> i keep on recieving from firebug an error saying GetElementById is not a function... any help will be greatly appreciated. thank you. I guess it is because it is 2am and had a few beers but i cannot get this to work and i know its pretty simple to do - see the code below: Code: {if ""|fn_needs_image_verification == true} {assign var="is" value="Image_verification"|fn_get_settings} <p{if $align} class="{$align}"{/if}>{$lang.image_verification_body}</p> {assign var="id_uniqid" value=$id|uniqid} {literal} <script language="javascript" type="text/javascript"> function reloadCaptcha() { captcha = document.getElementById("captureURLID").src; return captcha += 'reload'; } </script> {/literal} {if $sidebox} <p><img id="verification_image_{$id}" class="image-captcha valign" src="{"image.captcha?verification_id=`$SESS_ID`:`$id`&`$id_uniqid`&"|fn_url:'C':'rel':'&'}" alt="" onclick="this.src += 'reload' ;" width="{$is.width}" height="{$is.height}" /></p> {/if} <p><input class="captcha-input-text valign" type="text" name="verification_answer" value= "" autocomplete="off" /> {if !$sidebox} <img id="verification_image_{$id} captureURLID" class="image-captcha valign" src="{"image.captcha?verification_id=`$SESS_ID`:`$id`&`$id_uniqid`&"|fn_url:'C':'rel':'&'}" alt="" onclick="this.src += 'reload' ;" width="{$is.width}" height="{$is.height}" /> {/if} <img src="{$images_dir}/icons/icon_reload.png" height="25" width="25" alt="Reload Captcha Image" onclick="reloadCaptcha();" class="valign image-captcha" /></p> {/if} now the following works totally fine, when you click the captcha code changes..... "onclick="this.src += 'reload'" you will notice i have added a custom reload button image below this with a onclick calling a custom function "reloadCaptcha(); which i want to reload the captcha image above it - however it is not working, i have done the function so it grabs the src from the element ID, i have added 2 ID's to the IMG but cannot remember if you can have multiple IDs or not which if not could be causing the problem but not 100% sure how to include the smarty code for the generated ID on that image. Any ideas on the code above from having a quick glimps? as the code stands i get the error: Error: captureURL is null Many Thanks Hi guys I kinda needed help on jQuery/ javascript.. Here's the test page.. http://development.andrewfopalan.com/devpage/test.html# what I'm trying to do is like this.. http://trailers.apple.com/trailers/s...bandofmisfits/ the movie box... so far, I have made the cosmetics.. but the thing I was going to ask was.. when you click on the down arrow.. a popup dropdown list is going to show.. the problem is I am copying the same effect as the one with apple.. when you click outside of the popup dropdown list, the dropdown list should be fading out... but it wouldnt... I tried using doing.. it like this Code: $("#wrap" ).click(function () { $(".dropdown").fadeOut(); }); but the problem is.. whenever I click the down arrow button.. it continues to fadeout.. as soon as it fadesin... how should I do this? please guide me.. everything works just fine.. just this one.. I am really lost.. i the whole jquery code is in the page sirs... please help me pretty new to javascript/jquery.. |