JavaScript - Why Can't Delete Cookie-urgent
hi
I do not know why the cookies can't be deleted Code: function deleteCookies() { var splitC=document.cookie.split(";"); var i; for(i=0;i<splitC.length;i++) { var getName=splitC[i].split("="); var cookieDelete = getName[0].replace(/^\s+|\s+$/g, ''); document.cookie=cookieDelete+"=0;expires=Thu, 01-Jan-70 00:00:01 GMT"; } } Similar TutorialsI need some help for University cousework that has been sent and I hope someone here can help. I need to create a cookie (easy enough) and then populate that cookie with a word that is selected when you click a certain image. Imagine you have image1.jpg and image2.jpg when a user selects image1.jpg the cookie needs to store image1 and load page2.html If the user selects image2, then page2.html still needs to load but store the word image2 in the cookie. On the next page, the cookie is loaded and the page needs to load the css file associated with that word example: image1 = firstcss.css image2 = secondcss.css Is this possible? Thank you for all your help I have been searching the internet for thhe past hour trying to find this and searched this forum, I am trying to Delete my cookie with a button. On my websitr I have a cookie to remember the name of the user, I want them to be able to change their name with a button. so delete cookie. How can this be done? The cookie names its seld "UserName" if this helps. Hi everyone, I am using a jQuery cookie script to set the cookie of some elements on my website. One of the problems is that I need the cookie to not expire after one day, I need it to expire after a while (I'm going to start off with a year). Here's my script, the red part is what I've been editing. Code: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secu true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000 * 365)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } // CAUTION: Needed to parenthesize options.path and options.domain // in the following expressions, otherwise they evaluate to undefined // in the packed version for some reason... var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; Hi, i am new to javascript and i am giving a task to create a javascript page, i need a javascript that will calculate and generate a simple Quotation with total price of item selected and its quantity in a new page and in tabular form, i need this for 2 check-boxs that has the value, 2 dropdownlist and the price.
I'm a newbie to php and javascript. I want some checkbox to hide some rows of my table so i did a search and i found a few javascript codes but yet I couldn't make it work the way I wanted it. When I uncheck a checkbox ONLY the first table rows get hidden, the other tables don't? can't I ID some rows? Please I need help :( My javascript code is: Quote: <script type="text/javascript"><!-- function showHideTR(idx,vis) { var tbl,row; if(document.getElementById && document.getElementsByTagName) { tbl = document.getElementById('tbl'); if(!tbl || (idx >= tbl.getElementsByTagName('tr').length)) return; row = tbl.getElementsByTagName('tr')[idx]; } else if(document.all && document.all.tags) { // IE4 support tbl = document.all.tbl; if(!tbl || (idx >= tbl.all.tags('tr').length)) return; row = tbl.all.tags('tr')[idx]; } if(row) { if(!vis) { row.style.display = 'none'; } else { // conditional compilation to hide the try-catch blocks from IE4 /*@cc_on @if(!@_jscript || (@_jscript_version >= 5)) @*/ try { row.style.display = 'table-row'; } catch(e) { row.style.display = 'block'; } /*@elif(@_jscript_version < 5) row.style.display = 'block'; // for IE4 @end @*/ } } } function getStyle(el,styleProp) { var x = (typeof(el)=='string')?document.getElementById(el):el; if (x.currentStyle) var y = x.currentStyle[styleProp]; else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); return y; } window.onload = function() { if(!document.getElementsByTagName) return; var tds = document.getElementsByTagName('td'); for(var i=0;i<tds.length;i++) { tds[i].onclick = function() { alert(this.parentNode.tagName+' = display : '+getStyle(this.parentNode,'display')+ '\n'+this.tagName+' = display : '+getStyle(this,'display')); } } } // --> </script> <!-- <script type="text/javascript"> function showHideTR(idx,vis) { var tbl,val; val = (!vis)?'none':((document.defaultCharset && !window.home)?'block': 'table-row'); if(document.getElementById && document.getElementsByTagName) { tbl = document.getElementById('tbl'); if(idx >= tbl.getElementsByTagName('tr').length) return; tbl.getElementsByTagName('tr')[idx].style.display = val; } else if(document.all && document.all.tags) { // IE4 support tbl = document.all.tbl; if(idx >= tbl.all.tags('tr').length) return; tbl.all.tags('tr')[idx].style.display = val; } } </script> --> My option tags: Quote: <form action="#" onsubmit="return false;"> <ul> <li2><label for="cb0"><input type="checkbox" id="cb0" checked="checked" onclick="showHideTR(0,this.checked);"> Blah Blah</label></li> <li2><label for="cb1"><input type="checkbox" id="cb1" checked="checked" onclick="showHideTR(1,this.checked);"> Blah Blah2</label></li> <li2><label for="cb2"><input type="checkbox" id="cb2" checked="checked" onclick="showHideTR(2,this.checked);"> Blah Blah3</label></li> <li2><label for="cb3"><input type="checkbox" id="cb1" checked="checked" onclick="showHideTR(3,this.checked);"> Blah Blah4</label></li> </ul> </form> My php page: Quote: <?php $host = "localhost"; // your host name $username = "blah blah"; // your user name to access MySql $password = "blah blah"; // your password to access MySql $database = "blah blah"; // The name of the database $no = $_POST["sureno"]; //$link = mysql_connect($host,$username,$password); if (!$link = @mysql_connect($host,$username,$password,true)) {die('Could not connect:'. mysql_error()); } @mysql_query("SET NAMES 'latin5'"); @mysql_select_db($database) or die( "Unable to select database"); $sql="SELECT * FROM blah blah WHERE sure = '$no' ORDER BY 'id'"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } while($row=mysql_fetch_assoc($result)){ $bgcolor="#f1f1f1"; echo "<TABLE width=50% align=center cellpadding=0 cellspacing=0 id='tbl' summary='demonstration'> <tr>"; echo "<td bgcolor='dfdfdf' ><font face='arial,verdana,helvetica' color='#000000' size='3'>blah blah</font></td>"; echo "<td bgcolor='C0C0C0' ><font face='arial,verdana,helvetica' color='#FF0000' size='4'>" . $row['AB'] ."</font></td></tr>"; echo "<tr><td bgcolor='dfdfdf' ><font face='arial,verdana,helvetica' color='#000000' size='3'>blah blah</font></td>"; echo "<td bgcolor='dfdfdf'> <font face='arial,verdana,helvetica' color='#0080C0' size='2'>". $row['TR'] ."</font></td></tr>"; echo "<tr><td bgcolor='dfdfdf' ><font face='arial,verdana,helvetica' color='#000000' size='3'>blah blah</font></td>"; echo "<td bgcolor='dfdfdf' id='cb0'> <font face='arial,verdana,helvetica' color='#000000' size='3'>". $row['ML'] ."</font></td></tr>"; } mysql_free_result($result); ?> Hi Guys, I am implementing this Javascript in my summer internship. What I want to do is, 1) Show a Pop up alert with a Countdown timer( 10, 9, 8, 7 ....) after 5 minutes. 2) If user doesn't click "Ok" within the time, the page will automatically Redirect to another page. Eg- Login Page. 3) If the User clicks the "Ok" button the Page will not get re-direct. 4) Also, once the Timer countdown completes and the page redirection is done, the User when he will see the Login page will see an alert box saying. 'Your session has expired, plz login again' he clicks 'Ok' and Login again. I am very new to this Java script, but need to finish this project. Plz help me out. Hi I'm trying to create a javascript function that will ask a user for a character and check that character against a string containing other characters. If the character is present in the string the function should then ask the user to input another character. it should keep doing this until a charater is entered that doesnt appear in the check string. I am pretty new to javascript and have been working for about 2 days trying to get this to work. I have an assignment due next week 21.09.09 and need to get it sorted before then. Any help or pointers would be great. One stipulation that the assignment is asking for is that you have to use the indexOf method to interigate the string. I have attached the code below. Any help or pointers would be brilliant. var incorrectString = 'abcdef'; var correctString = 'ghi'; function getInput(aString) { } getInput(incorrectString + correctString); here's what I have so far Code: <html> <head> <script> MONTHS_OF_THE_YEAR = 'janfebmaraprmayjunjulaugsepoctnovdec'; MILLISECONDS_DAY = 1000*60*60*24; MILLISECONDS_YEAR = 1000*60*60*24*365.2424; LIFE_EXPECTANCY = 1000*60*60*24*365.2424*67.2; var daysArray = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); var yearBirth = ''; yearBirth = prompt('Please enter your year of birth'); var monthBirth = ''; monthBirth = prompt('Please enter your month of birth'); monthBirth = monthBirth.slice(0,3); monthBirth = monthBirth.toLowerCase(); monthBirth = MONTHS_OF_THE_YEAR.indexOf(''+monthBirth)/3; var dateBirth = ''; dateBirth = prompt('Please enter your date of birth'); var usersInputDate = new Date (yearBirth, monthBirth, dateBirth); var dd = new Date((monthBirth+1).toString() + "/" + dateBirth + "/" + yearBirth); dd=dd.getDay(); var now = new Date(); usersInputTime = (usersInputDate.getTime()); usersInputTime = parseInt(now.getTime()-usersInputTime); var ageYears = (usersInputTime/MILLISECONDS_YEAR); var ageDays = (usersInputTime/MILLISECONDS_DAY); var avgLife = (usersInputTime/LIFE_EXPECTANCY*100); document.writeln('<h1>It\'s about time...</h1>'); document.writeln('<ul>'); document.writeln('<li> </li>' </script> </head> <body> </body> </html> I need to do the following and have no idea Quote: What will be output (to the document using write())? A heading 1 title with the text It's about time... An unordered list containing appropriate wording as strings concatenated with: The weekday name for the user's birth date Use the day of the week number as an index into the weekday names array The user's age in years Present this as a fixed format number with 2 decimal places The user's age in days Present this as a fixed format number with 0 decimal places The percentage of an average life expectancy Present this as a fixed format number with 0 decimal places please help i need to get this done tonight can any one please help me out with the code. I am passing an URL for ex: www.example.com?req=23¶m=25 What i need to do is I need to remove the parameters after "?" which I did using the spilt method, Can anyone help me out now how do I send the complete URL with the parameters as hidden. what I mean is..my URL should look like www.example.com. but the second part (parameter shud be hidden). im new beginner for jsp coding and java script programming..here,i have a few question about date calculation. 1.duration date between date signed and expired date = display in year 2. from expired date available years, month and day minus with Date Today 3. how to use IF ELSE statement to display status active or inactive (example : active status if more then 8 month or inactive status if less then 8 month) this is my coding...it's right? for years <script language="JavaScript" type="text/javascript"> /*<![CDATA[*/ function DaysMonths(but,nme,op){ var frm=but.form; var dates=frm[nme]; for (var i=0; i<dates.length; i++){ var date=dates[i].value.split('-'); dates[i].date=new Date(date[0]*1,date[1]-1,date[2],0,0,0,0); } var days=(dates[1].date-dates[0].date)/1000/60/60/12; years=(dates[1].date.getFullYear()-dates[0].date.getFullYear()); frm[op].value=years+' years'; } /*]]>*/ </script> i have output : 5 years for month and day <script language="JavaScript" type="text/javascript"> /*<![CDATA[*/ function DaysMonth(but,nme,op){ var d = new Date(); var frm=but.form; var dates=frm[nme]; for (var i=0; i<dates.length; i++){ var date=dates[i].value.split('-'); dates[i].date=new Date(date[0]*1,date[1]-1,date[2],0,0,0,0); } var days=(dates[1].date-dates[0].date)/1000/60/60/24s; var months=dates[1].date.getMonth()-dates[0].date.getMonth(); months=(dates[1].date.getFullYear()-dates[0].date.getFullYear()-d.getDate())*12+(months<0?months:-months); frm[op].value= months + ' month ' +days+ ' day '; } /*]]>*/ </script> my output i have like this : 48 month 1826 day i set date format in my sql like this date signed = 2008-11-18 date expired = 2013-11-18 how can i have output like this for for duration (date expired - date signed) minus date for today = 3 year, 42 month 1826 day sorry for my thread post this morning...not mean like that... I am a beginner so please help ASAP. When I validate my code in validate.w3.org: document.write("<img src='" + myNum +".jpg'/>"); I got an error that said: --- required attribute "alt" not specified Hai everyone, I am a newbie to javascript.I have a scenario where I have two sets of textboxes,one that holds the percentage and other holds the percenteage value. Below them,I have a total value of which the percentage values will be stored. Can anyone help me in writing the javascript code in finding the percentage value of the total number given below and storing it in a text box. Any help,I need it urgent I have a page in html, containing some text like " ABCDEFGHIJKL" etc. This text has also a website link (hyperlink) with it. This website link changes on each refresh of page. Such link changes due to javascript runing behind on it. I just want this link each time stored in a PHP variable. Such text always appears on a certain position on the page (X,Y). Can you please help me on it.? I can provide additional details on request. Your early answer is required. Regards Ahmed Taufiq I have been trying for hours to do the following: - Change the background of a div by clicking a link from another div tag. - It also needs to change back when clicked again. I know there are alot of experienced coders out there and I'm eager to learn... help would be appreciated! Hi I'm trying to download the security image from this site (at the bottom): http://pacesalsa.promotionexpert.com...2/register.jsp However, every time one refreshes the image, the image changes (obviously). So, I'm trying to figure out how to download the current image on the page to a jpg or png (or any image file type). Could someone please tell me how to do this? Thanks. I want to insert image instead of those empty boxes.......can someone help me please...... <script type="text/javascript"> document.write("<html><head><title>My PhotoCollage</title></head><body>"); function makeDiv() { var r = Math.floor(Math.random()*256); var g = Math.floor(Math.random()*256); var b = Math.floor(Math.random()*256); var wh = 25 + Math.floor(Math.random()*444); var lr = (Math.random()<.5) ? "top":"right"; var bw = 1 + Math.floor(Math.random()*12); var bs = (Math.random()<.5) ? " solid":"dotted"; var dc = (Math.random()<.5) ? "Dog" : "Cat"; var Img = Math.floor(Math.random()*256); document.write("<div style=\"float: "+lr+";"+ "width: "+wh+"px;"+ "height: "+wh+"px;"+ "border: rgb(" + g + "," + b + "," + r + ") "+bw+"px "+bs+";"+ "background-color: rgb(" + r + "," + g + "," + b + ");"+ "image: "\">"+dc+ "</div>"); } var i; var count = Math.floor(Math.random()*100) + 5; for (i=0; i<count; i++) makeDiv(); document.write("</body></html>"); </script> ===================[ URGENT ]================= confirm_state is not working properly..as it uses sajax..it is supposed to get the value of the state ..but the state being a string not working...please help.. ........................urgent......... <? function search_states($str) { //print $str; //print "<br><pre>"; $number=explode('-',$str); //print_r($number); //print $number[0]; if(count($number)==1) { $table='states'; $data=array('*'=>''); $fldarray=array("state"=>$number[0]); $val=dataSelectSearch($table,$data,$fldarray,$extra,$orderArray,$orderType); // print "<pre>"; // print_r($val); for($i=0;$i<count($val);$i++) { $state_name=$state_name."##".$val[$i]['state']; } return $state_name; } else { $strt_val=ord($number[0]); // Ascii of first character $end_val=ord($number[1]); // Ascii of last character //print chr($end_val); for($j=$strt_val;$j<=$end_val;$j++) { $table='states'; $data=array('*'=>''); $fldarray=array("state"=>chr($j)); $val=dataSelectSearch($table,$data,$fldarray,$extra,$orderArray,$orderType); for($m=0;$m<count($val);$m++) { $state_name=$state_name."##".$val[$m]['state']; } } return $state_name; } } ?> <script> function confirm_state1(msg) { // =============================== [subcategory follows ] ========================= //alert(msg); var value=msg; var arr=Array(); arr=value.split("##"); for(i=1;i<=(arr.length-1);i++) { //var new_val; //alert(i); //var int=Integer.valueOf(arr[i]); document.getElementById('innercontent').innerHTML=document.getElementById('innercontent').innerHTML+ "<br> <a href='javascript:void(0);' onclick='document.getElementById(state_name).value="+arr[i]+";' class='small_link1'>"+arr[i]+"</a>"; //document.getElementById('all_state').innerHTML=''; //alert(document.getElementById('innercontent').innerHTML); } } function showname(val) { //alert(msg1); alert(val); document.getElementById('state_name').value=val; document.getElementById('all_state').style.display='none'; } function findstate(str) { //alert(str); document.getElementById('innercontent').innerHTML=''; document.getElementById('all_state').style.display='inline'; var str1=str; x_search_states(str1,confirm_state1); } </script> I am not a JavaScript resource , on an urgent basis I need to create a GUI screen with the help javascript for running reports i.e. the parameters would be passed to reports that are to be run. My requirement is to create : User friendly drop down box A date field with calender in it so taht value can be selected from the calender and passed on to the database. A option on the GUI that would create a csv file on the server. is it possible to open all file of a folder with multiple folders inside in turn opening all files. basically i have some sites i need to fully edit but i rather work with every file from the website open i need to open every file in a folder of files in other folder help i cant go one by one it would take forever.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get personal details</title> <!-- meta tags --> <meta name="keywords" content=""> <meta name="description" content=""> <!-- stylesheets --> <link rel="stylesheet" href="css/reset.css" type="text/css"> <link rel="stylesheet" href="css/common.css" type="text/css"> <!-- javascript --> <script src="js/jquery-1.3.2.min.js"></script> <!--conditional comments --> <!--[if IE]> <script src="js/html5.js"></script> <![endif]--> <script language="javascript" type="text/javascript"> function validName(n,c,l,d) { if(n.length == 0) { window.alert('A name must not be empty!'); return false; } if(c.length == 0) { window.alert('A country must not be empty!'); return false; } j = -1; for(i = l.length-1;i > -1;i--) { if(l[i].checked) { j = i;i = -1; } } if(j == -1) { window.alert('A like must not be empty!'); return false; } t = -1; for(s = d.length-1;s > -1;s--) { if(d[s].checked) { t = s;s = -1; } } if(t == -1) { window.alert('A dislike must not be empty!'); return false; } return true; } </script> </head> <body class="home"> <article id="page-content"> <section> <hgroup> <h2>Get personal details</h2> </hgroup> <form method="get" action="show_details.php" onSubmit="return validName(this.name.value,this.country.value,this.likes,this["dislikes[]"]);"> <table class="bordered"> <caption>Personal details form</caption> <tr> <th class="col1"> Property </th> <th class="col2"> Value </th> </tr> <tr> <td class="col1"> Name </td> <td class="col2"> <input type="text" name="name" size=30> </td> </tr> <tr> <td class="col1"> Age </td> <td class="col2"> <select name="age"> <option> 0-10 </option> <option> 11-20 </option> <option> 21-30 </option> <option> 31-40 </option> <option> 41-50 </option> <option> Over 50 </option> </select> </td> </tr> <tr> <td class="col1"> Country </td> <td class="col2"> <input type="text" name="country" size=30> </td> </tr> <tr> <td class="col1"> Likes </td> <td class="col2"> <input type="radio" name="likes" value="swimming">Swimming<br> <input type="radio" name="likes" value="running">Running<br> <input type="radio" name="likes" value="dancing">Dancing<br> <input type="radio" name="likes" value="biking">Biking<br> <input type="radio" name="likes" value="surfing">Surfing<br> </td> </tr> <tr> <td class="col1"> Dislikes </td> <td class="col2"> <!-- The value of dislikes is an array of checked values --> <input type="checkbox" name="dislikes[]" value="dogs">Dogs<br> <input type="checkbox" name="dislikes[]" value="cats">Cats<br> <input type="checkbox" name="dislikes[]" value="birds">Birds<br> <input type="checkbox" name="dislikes[]" value="fish">Fish<br> <input type="checkbox" name="dislikes[]" value="plants">Plants<br> </td> </tr> <tr> <td class="col1"> Description </td> <td class="col2"> <textarea name="description" rows=6 cols=30></textarea> </td> </tr> <tr> <td colspan=2 style="text-align: center"> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"> </td> </tr> </table> </form> </section> </article> </body> </html> I cant for the life of me find out why it wont display the javawindow anymore? suppose to pop up when you dont enter a name, country, check a radio or checkbox |