JavaScript - How To Return To Original Image
Needless to say, I am no coder! I dabble with it only when I have to.
I have images/text linked to buttons that fade in “onclick” from “original” images/text . I’ve gotten this to work great with text or image but… I would like the images/text to fade out and return to “original” images/text after a time limit and or no mouse use. Here’s the code I have so far: Code: $(document).ready(function(){ $('.image1).click(function() { $('#original_image).fadeOut(300, function() { var the_image = $('#image1).html(); $(this).html(the_image).fadeIn(300); }); }); Thanks Similar TutorialsHi, I'm trying to integrate an address finder (http://www.craftyclicks.co.uk/) into my shopping cart (OsCommerce). I can get it to work but I need to add my own functionality. I'm not very experienced with JavaScript and my head has entered an infinite loop by now. The problem is that the address finder script can change the selected country in a drop-down list depending on the postcode entered by the user (using the onblur event handler). What I need it to do is to remove all other countries depending on the postcode. I can get it to remove all other countries but how do i return to the original list of countries when the postcode is changed again? Once all other counties are removed, the drop-down list will obviously only have one option left... I guess the question is also how does a function remember what it has done before, when it is called again? I have written this short test script as it is easier to work with than the craftyclicks oscommerce contribution: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>HTML Template</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <script type="text/javascript"> //<![CDATA[ function store(element) { // store values var cl = element; var text_list = new Array(); var value_list = new Array(); var length = cl.length; for (var foo=0; foo<length; foo++) { text_list[foo] = cl.options[foo].text; value_list[foo] = cl.options[foo].value; alert("text array " + foo + " " + text_list[foo]); alert("value array " + foo + " " + value_list[foo]); } populate(cl, text_list, value_list); } function populate(element, text, value) { // populate options with previously stored values var cl = element; var length = cl.length; cl.options.length=0; for (var bar=0; bar<length; bar++) { cl.options[bar]= new Option(text[bar], value[bar], false, false); } } function crafty_set_country(code) { var cl = document.getElementById('select'); store(cl); for (var i=0; i<cl.length; i++) { if (cl.options[i].value == code) { alert(cl.options[i].value + " found"); var value = cl.options[i].value; var text = cl.options[i].text; cl.options.length=0; cl.options[0]=new Option(text, value, true, true); /* for (var j=0; j<cl.length; j++) { alert("second loop " + cl.options[j].text); if (cl.options[i].value != code) { cl.options[j] } } */ } else { alert(cl.options[i].value); } } } //]]> </script> </head> <body> <form> <select id="select"> <option value="10">ten</option> <option value="20">twenty</option> <option value="30">thirty</option> <option value="40">fourty</option> <option value="50">fifty</option> <option value="60">sixty</option> </select> <input type="button" value="remove" name="button" onClick="crafty_set_country(50)"> <input type="button" value="repopulate" name="button" onClick="crafty_set_country(100)"> </form> </body> </html> Many thanks! Martin i have image button i need to display image .if the size of the image button is 100*100 and image size is 50*50 .the remaining space of the image button should be empty.the image should not stretch. can any one guide me i am new to programming Thanks in advance!!! I am trying to write a custom BBcode for a forum I moderate. I don't have the licensing information because its not my forum and i am just a moderator. If anyone wants to verify the legitimacy of the forum I work for please PM me and I will try and get you any information I can. This code that I has works perfect in EditRocket, but when I add it to the custom BBcode the image does not resize. Original EditBucket Code: Code: <html> <head> <script type="text/javascript"> function show_confirm(testimg) { var theImg = document.getElementById('testimg'); var theWidth = theImg.width; var theHeight = theImg.height; if (theWidth<250) { theImg.width = theWidth; theImg.height = theHeight; } else { theImg.width = 250; theImg.height = theHeight*(250/theWidth); } } </script> </head> <body> <img id="testimg" onload="show_confirm(testimg)" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png"> </body> </html> vBulletin Custom BBcode: title: Test Image bbcode tag name: timage Replacement: Code: <script type="text/javascript"> function show_confirm(testimg) { var theImg = document.getElementById('testimg'); var theWidth = theImg.width; var theHeight = theImg.height; if (theWidth<250) { theImg.width = theWidth; theImg.height = theHeight; } else { theImg.width = 250; theImg.height = theHeight*(250/theWidth); } } </script> <body> <img id="testimg" onload="show_confirm(testimg)" src="{param}"> </body> Example: [timage]http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png[/timage] Description: Embed imaged inline with forum Option: no I don't understand the logic of Break, Return False, Return True. It was never really covered in our college class, and I see everyone using it. I got an A in the class, if that 'proves' that I really tried to apply myself. NOTE: I understand what the function is doing. I just don't understand WHEN to use break, return false or return true if the the translator can determine the conditional statements. PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } else return false; } if the the translator can determine the conditional statements, why not write it like this: PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; // what's the point for the 'break'? Won't the rest of the code be ignored since it passed the first condition? } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } // why not leave the last else out? is it just a 'safety' catch, in case something other than true or false is inputted? else return false; // what's the point? } Questions: Why use return true, if the translator knows it's ture? Why use "return false" if the translator knows it's false and the alert window has already gone up? why not use "break" to stop the code? Why use the "return false" at the end "else" statement? Hi room, Hey, I opened up the source code for this page in google chrome and since i'm learning javascript, i wanted see if i could "read" it and figure out what was going on. I'm am having the hardest time understanding "return false" and "return true". Could someone step me through this via interpreting this code (in bold typeface): Code: var DefaultValue = 'Search'; function clearSearch() { if (document.searchForm.q.value == DefaultValue) { document.searchForm.q.value = ''; } } function validateSearchHeader() { if ( document.searchForm.q.value == '' || document.searchForm.q.value.toLocaleLowerCase() == DefaultValue.toLocaleLowerCase() ) { alert('Please enter at least one keyword in the Search box.'); document.searchForm.q.focus(); return false; } return true; } Thanks! Hi, Because I'm using an asp script to submit this form, I cannot do a validation on the submit and so have chosen to do the validation with the onblur and the onmouseout functions. The validation works well for the checking the first input, id CommenterName. If it's blank, the alert displays and then the cursor is moved to the email check. When the alert is dismissed the focus returns to the first input, but, and this is the problem, returning to the first input, triggers the second alert. How do I return the focus to the first field without triggering the next alert? Changing the order of the inputs in not an option. Code: function checkCompletitionName(){ if (document.getElementById("CommenterName").value.length == 0) { document.getElementById("CommenterName").style.backgroundColor = "#efefef"; alert("Please type your name."); document.getElementById("CommenterName").focus(); return; } else { document.getElementById("CommenterName").style.backgroundColor = "white"; } } function checkCompletitionEmail(){ if (document.getElementById("Email").value.length == 0 || (document.getElementById("Email").value.search("@") == -1 || document.getElementById("Email").value.search("[.*]") == -1)) { document.getElementById("Email").style.backgroundColor = "#efefef"; alert("Please check the email address for errors."); return; } else { document.getElementById("Email").style.backgroundColor = "white"; } } function checkCompletitionComment(){ if (document.getElementById("Comment").value.length == 0) { document.getElementById("Comment").style.backgroundColor = "#efefef"; alert("Please type your comment."); return; document.getElementById("Comment").focus(); } else { document.getElementById("Comment").style.backgroundColor = "white"; } } the HTML code: Code: <form name="form1" method="get" action="/asp/formmail.asp"> <p> <label class="labelContact">Select Category:</label> <select class="inputContact" name="category" id="category"> <option selected="selected" value="support" id="support">Support</option> <option value="sales" id="sales">Sales</option> <option value="other" id="other">Other</option> </select> </p> <p> <label class="labelContact" for="CommenterName">Name <span class="redasterisk">*</span>:</label> <input size="42" class="inputContact" name="nameCommenter" id="CommenterName" onblur="checkCompletitionName()" type="text" /> </p> <p> <label class="labelContact" for="Email">Email Address<span class="redasterisk"> *</span>:</label> <input size="42" class="inputContact" name="email_address" id="Email" onblur="checkCompletitionEmail()" type="text" /> </p> <p> <label class="labelContact" for="Phone">Phone Number:</label> <input id="phoneAreaCode" class="inputContact" onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3" /> - <input id="phonePrefix" onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3" /> - <input id="phoneLastFour" onKeyUp="return autoTab(this, 4, event);" size="5" maxlength="4" /> </p> <p> <label class="labelContact" for="RegistrationNo">Registration Number:</label> <input size="42" class="inputContact" name="registration" id="RegistrationNo" type="text" /> </p> <p> <label class="labelContact" for="CompanyName">Company Name:</label> <input size="42" class="inputContact" name="company_name" id="CompanyName" type="text" /> </p> <p>Comments <span class="redasterisk">*</span>:</p> <p><textarea rows="5" cols="58" name="comment" id="Comment" onmouseout="checkCompletitionComment()"></textarea></p> thank you for your help 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! I'm trying to create a demo to display a new way of showing our data. I thought I remembered this being pretty simple but I'm hitting a snag. The table, the mouse over, and the check row by clicking on the row all work separately but when the check row by clicking function is on, seen in the first row, the checkbox stops working. Any insight into why this may be true? Any help is greatly appreciated Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> function selectRow(row) { var firstInput = row.getElementsByTagName('input')[0]; firstInput.checked = !firstInput.checked; } </script> </head> <body> <table id="tbl" border="2"> <thead> <tr> <td></td> <td>First Row</td> <td>Second Row</td> <td>Third Row</td> </tr> </thead> <tbody> <tr onclick="selectRow(this)" onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>1</td> <td>1</td> <td>1</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>2</td> <td>2</td> <td>2</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>3</td> <td>3</td> <td>3</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>4</td> <td>4</td> <td>4</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>5</td> <td>5</td> <td>5</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>6</td> <td>6</td> <td>6</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>7</td> <td>7</td> <td>7</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>8</td> <td>8</td> <td>8</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>9</td> <td>9</td> <td>9</td> </tr> <tr onmouseover="this.style.cursor='hand'"> <td> <input type="checkbox" class = "chcktbl"/> </td> <td>10</td> <td>10</td> <td>10</td> </tr> </tbody> </table> </body> </html> I am looking to use a similar method as facebook chat does, where it alternates between the original title text and 'friendsName has sent you a message!...' how can I do this ? <script language="JavaScript"> function changeColor(cell_id){var state1="#dde6ed"; var state2="#ffc20e"; var cellid = new Array ("id1", "id2", "id3", "id4", "id5", "id6"); for(var i = 0; i < cellid.length; i++){var nav = document.getElementById(cellid[i]); if(cellid == nav.id){nav.style.backgroundColor=state2;} else {nav.style.backgroundColor=state1;}}} </script> Can anyone tell me what is wrong with this script. I put an onClick= changeColor(this);" in my <td> tag to call the script but still not working. i have this in my javascript code but have no idea on how a returned value works/where does it return to???? what do i do/or can i do with a value that gets returned??? i am asking this so i can learn on how to use it cos i am new to all this and dont know how it works...please show/explain to me please? thanks here my full code: PHP Code: <?php use_stylesheets_for_form($form) ?> <?php use_javascripts_for_form($form) ?> <html> <head> <script type="text/JavaScript"> function refreshPage(s) { window.location.reload(); if((s.options[s.selectedIndex].value) = "zed-catcher") { var $index = s.selectedIndex; var $value = s.options[$index].value; alert (s.selectedIndex); alert ($value); window.location.reload(); [COLOR="Red"]return &value; //where does it return to ???? how/what to do with a return value???[/COLOR] } } </script> </head> </html> <body> <form action="<?php echo url_for('adminservice/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" '?>> <?php if (!$form->getObject()->isNew()): ?> <input type="hidden" name="sf_method" value="put" /> <?php endif; ?> <table > <tfoot> <tr> <td colspan="2"> <?php echo $form->renderHiddenFields(false) ?> <a href="<?php echo url_for('adminservice/index') ?>">Back to list</a> <?php if (!$form->getObject()->isNew()): ?> <?php echo link_to('Delete', 'adminservice/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?> <?php endif; ?> <input type="submit" value="Save" /> </td> </tr> </tfoot> <tbody> <?php echo $form->renderGlobalErrors() ?> <tr> <th><?php echo $form['name']->renderLabel() ?></th> <td> <?php echo $form['name']->renderError() ?> <?php echo $form['name']?> </td> </tr> <tr> <th><?php echo $form['logo_url']->renderLabel() ?></th> <td> <?php echo $form['logo_url']->renderError() ?> <?php echo $form['logo_url'] ?> </td> </tr> <tr> <th><?php echo $form['call_center_number']->renderLabel() ?></th> <td> <?php echo $form['call_center_number']->renderError() ?> <?php echo $form['call_center_number'] ?> </td> </tr> <tr> <th><?php echo $form['catcher_id']->renderLabel(); $catcher_id = $form->getObject()->getCatcherId(); $catcher = LpmCatcherPeer::getByCatcherId($catcher_id); $catcher_name = $catcher->getName(); ?></th> <td> <?php echo $form['catcher_id']->renderError() ?> [COLOR="Red"]<select name="services" onchange="refreshPage(this.form.services)">[/COLOR] <?php $catcher_names = LpmCatcherPeer::getByAllNames(); foreach($catcher_names as $row) { ?> <option value="<?php echo $row->getName()."/".$row->getId();?>" <?php if($row->getName() == $catcher_name) echo ' selected="selected"'; ?> ><?php echo $row->getName();?></option> <?php } [COLOR="Red"]if ($row->getName() == "zed-catcher") //just thought with the return in my java script i can pass the newley selected value back to here and if it meets the if i echo these lines?? { echo $form['service_code']->renderLabel(); echo $form['service_code']->renderError(); echo $form['service_code']; } [/COLOR] ?> </select> </td> </tr> <tr> <th><?php echo $form['price_description']->renderLabel() ?></th> <td> <?php echo $form['price_description']->renderError() ?> <?php echo $form['price_description'] ?> </td> </tr> </tbody> </table> </form> </body> thanks! i'm trying to get some information with this code from my database: Code: function getTableSize(tableName){ db.transaction ( function(tx) { tx.executeSql ('SELECT * FROM '+ tableName,[] , function(tx, r) { return r.rows.length; } ); } ); } but it doesnt work and i cant figure why what i want is that this function return the table size to one variable in another function...something like: Code: var groupTableSize = getTableSize('groups'); i achieved to make a chain: Code: function getId(id) { id_elem = document.getElementById(id); return { color:function(e){ id_elem.style.color = e; } }; } so this can be getId("test").color("red"); but what happens if i want to do that? Code: function getId(id) { id_elem = document.getElementById(id); return id_elem; return { ????...... how can i chain if i use return in the first place? I have a javascript that takes information from a form and recompiles that information into a readable shift report. The problem I am having is with returns in the textareas. I tried: Code: theReport = theReport.replace(" ","<br>" but that space puts the rest of the var on a different line and screws with the results. How can I replace a return with <br>? I want the output to be this way Student: Doe, John eMail: jd@email.com Course ID: COIN-O70A.01 ----------------------- Can any one pls help me with the display. If I use alert instead of return then I works. But I need to display it in the document. Code: <html> <head> <title>Variable - Examples 1</title> <script type="text/javascript"> function Student(firstName, lastName, email,courseID){ this.firstName = firstName; this.lastName = lastName; this.email = email; this.courseID = courseID; } Student.prototype = { constructor : Student, toString : studentInfo }; function studentInfo(){ return this.firstName + "," + this.lastName + '\n'+ this.email + '\n' + this.courseID; } var student = new Student("Doe", "John", "Doeohn@gmail.com","COIN 70A.01"); </script> </head> <body> <script type="text/javascript"> document.writeln(student.toString()); </script> </body> </html> Im working on a function where i need to return the active elements ID. the element will have class="main" id="1" onmouseover="showSub()"> Would someone be able to write me a simple function which simply puts the elements ID number in an alert box? I can figure out the rest i need from that . Thanks, Tom hi,i don't understand about the jquery basic example the code is below PHP Code: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $('p').addClass(function(n){ return 'par_' + n; }); }); }); </script> <style type="text/css"> .par_0 { color:blue; } .par_1 { color:red; } </style> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Add classes to p elements</button> </body> </html> i want to understand about the how is work function(n){ in the function a and how work return function return 'par_' + n; thanks mate hi, i wanna get the value from javascript to php variable. here is my code, <html> <body> <select name="drop" size="10" onchange="drp_selectd_value(this)"> <option>One</option> <option>Two</option> <option>Three</option> <option>Four</option> <option>Five</option> </select> <?php echo "The PHP value".'<script>value_return();</script>'; $p='<script>y;</script>'; ?> </body> </html? <script> var x; var y=100; function drp_selectd_value(sdf) { x=sdf.value; alert("Value is : " +x); value_return(x); } function value_return(val) { alert("Second Function calling : "+val ); return val; } </script> This code does not working!!! How can i fix tis problem???I m expecting for the reply.. Thanks in advance Hello, How can this be made to return confirmation? <form id="score_form" method="post" action="addscore.php"><input id="score" name="score" value="" type="hidden"><img id="collect" style="cursorointer;height: 37px; width: 100px; margin-top: 13px;" src="./collectlive.gif" onclick="collect_points();"></form> Letsay the confirmation window would say"ARE YOU SURE" Have a jsp page with 10 editable fields and in last Add Button.Now when user edit a field from value 10 to 20(example)and click on Add .Value will be changed and focus will return to the same field.similarly for other fields.how to to .any code sample?
|