JavaScript - Javascript Reset To Lowest Value?
Hi i have very little javascript experience and need some help, i have made a rest button to reset select forms to there top value using this
function ResetForm(){ document.getElementById('canvas').value = 6 ; document.getElementById('acrlyic').value = 10 ; } is there a way to make so instead of having "value = 6;" it would just reset to the option with the smallest value? it will be used on multiple pages were the same name select will have different values on the options Similar Tutorialssorry for my poor english I have 2 boxfield in my search engine...when i write somthing on my 1st text box and press the clear button it clear me the thing i wrote in the text field.... when i write somthing and drag it from 1st text box to the 2nd and then press the clear button.the letter in the 2nd textfield jump the 1st one.....and doesnt clear herself... what can couse it ? Hello. I open a new forum thread as adviced by jmrker. Old forum thread related to this topic: http://www.codingforums.com/showthre...8#post12243889 Here is my code, based on the latest Philip M's work : Code: <html> <head> <script type = "text/javascript"> var cday; var timeInSecs; var ticker; function getSeconds() { var now = new Date(); var nowtime= now.getTime(); // time now in milliseconds var countdowntime = new Date(now.getFullYear(),now.getMonth(),now.getDate(),20,0,0); // 16 hrs = 4 pm // countdowntime - change time hh,mm,ss to whatever time required, e.g. 7,50,0 (0750) var dy = 5 ; // Friday (day 5) - change for other days 0-6 var atime = countdowntime.getTime(); var diff = parseInt((atime - nowtime)/1000); // positive if date is in future if (diff >0) { cday = dy - now.getDay(); } else { cday = dy - now.getDay() -1; } if (cday < 0) { cday += 7; } // aleady passed countdown time, so go for next week if (diff <= 0) { diff += (86400 * 7) } startTimer (diff); } function startTimer(secs) { timeInSecs = parseInt(secs); ticker = setInterval("tick()",1000); tick(); // to start counter display right away } function tick() { var secs = timeInSecs; if (secs>0) { timeInSecs--; } else { clearInterval(ticker); // stop counting at zero getSeconds(); // and start all over again! } var days = Math.floor(secs/86400); secs %= 86400; var hours= Math.floor(secs/3600); secs %= 3600; var mins = Math.floor(secs/60); secs %= 60; var result = days +':'; result += ((hours < 10 ) ? "0":"" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0":"" ) + secs + ""; document.getElementById("countdown").innerHTML = result; } </script> </head> <body onload = "getSeconds()" style="background-color: #ffffff;"> <br><br> <div id="CountDownLogo" style="background-color: #ffffff; width:300px; height: 180px; background-image:url(ScreenShot002.png) "> <span id="title" style="font-family: arial; font-size: 20; font-weight: bold; color: #ffffff; position: relative; top:27px; left:60px; z-index:1;">Weekend Cup 2012</span> <br><br> <span id="countdown" style="font-family: arial; font-size: 25; font-weight: bold; color: #3b3b3b; position: relative; top:34px; left:127px; z-index:1;"> </span> <br><br> </div> </body> </html> My event takes place at 8pm on fridays. To see if this script works in all conditions, I change my system date and time (to see if the script displays the good remaining duration). TESTS: Friday - So I set my system date on friday but at different times. When I do that, everything seems to work fine. - If I chose an earlier time (11am for example), it's fine too. - If I chose 7:59:45 pm (and wait a few seconds) I can see the countdown resetting and displaying 6 days 23 hours 59 min 59 sec. So it's fine too. Saturday - But if I chose saturday 00:00:01 am it doesn't work. It displays 0:19:59:59 (as if the event occured the same day, saturday). - And if I chose saturday 7:59:45 pm, the counter resets and displays 6 days 23 hours 59 min 59 sec.. Which is also wrong because it would mean that the even occurs on saturdays 8pm. Sunday - Same for sunday (the same errors like saturdays) Btw, could it be possible to display on the HTML page, all variable values ? This could help me understand how the script is done. (I am a poor coder). Thank you very much. Hi, I am new to Javascript and am having a few problems with what are probably very simple issues. In the attached code how do I prevent "NaN" and "Infinity" error messages in the result1-3 fields. I have had a go at the isNAN() etc functions but I just cant seem to get the syntax right. How would I restrict the results to 3 decimal places? I also want to evalaute the three results and populate the lowest field with a text response indicating which of the results has the lowest value, ie "Result 1 is the lowest value". Thanks for any assistance you can offer, Cheers Iain Code: <html> <head> <script language="javascript" type="text/javascript"> <!-- --> function cost1() { document.calc.result1.value=document.calc.num1.value*100/document.calc.num2.value; } function cost2() { document.calc.result2.value=document.calc.num3.value*100/document.calc.num4.value; } function cost3() { document.calc.result3.value=document.calc.num5.value*100/document.calc.num6.value; } </script> </head> <body> <form name="calc"> <table> <tr> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="num1" size="10" style="text-align: center" /> </td> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="num2" size="10" style="text-align: center" /> </td> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="result1" size="14" style="text-align: right" /> </td> </tr> <tr> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="num3" size="10" style="text-align: center" /> </td> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="num4" size="10" style="text-align: center" /> </td> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="result2" size="14" style="text-align: right" /> </td> </tr> <tr> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="num5" size="10" style="text-align: center" /> </td> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="num6" size="10" style="text-align: center" /> </td> <td align="center"> <input type="text" value="0" onfocus="if(this.value == this.defaultValue) this.value = ''" name="result3" size="14" style="text-align: right" /> </td> </tr> <tr> <td align="center"> <input type="button" style="font-size: 12pt; color: #oooooo" value="Calculate" onClick="cost1();cost2();cost3()" /> </td> </tr> <tr> <td align="center"> <input type="text" name="lowest" size="14" style="text-align: center" /> </td> </tr> </table> </body> </html> Hi i have a problem, i've been trying to fix this for the whole day pls see my code below Code: for ($o = 0; $o <= $totalclass; $o++) { for($i = 1; $i <= 45; $i++) { if ($_SESSION['classification'][$o] == $i) { $sql2="SELECT ClassDesc FROM tblclass WHERE ClassID = '$i'"; $result2=mysql_query($sql2); // If successfully queried if($result2) { while ($row2 = mysql_fetch_assoc($result2)) { $ClassDesc2 = $row2['ClassDesc']; } } //echo $ClassDesc2; ?> <tr> <td bgcolor="FAFAF6" class="small" valign="top">Class <? echo $i; ?></td> <input type="hidden" name="<? echo "classid[]"; ?>" value="<? echo $i; ?>"> <td bgcolor="FAFAF6"> <textarea name="<? echo "specification[]"; ?>" COLS="50" ROWS="6" class="small" wrap="virtual" tabindex="<? echo $i; ?>"><? echo $ClassDesc2;?></textarea> <input type="button" value="Reset" onclick="window.reset();" name="reset"> </td> </tr> <? } } } i've trying to create a button or image to reset one textarea (from whole array) and so far i've been unsuccessful. i've seen this on other website and i know it is possible to do this, pls help! i want to rest IE seting like font size and zoom when user enter my site how can i do that
<script type="text/javascript"> function resetForm() { //noofrow = document.getElementById("NoOfRow").value; //form = document.getElementByID('form1'); //noofrow.reset(); d1=document.getElementById("textfield").value; d1=""; d1.reset(); return false; } </script> </head> <body> <form id="form1" name="form1" method="post" action=""> <p> <label> <input type="text" name="textfield" id="textfield" /> </label> </p> <p> <label> <input type="text" name="textfield2" id="textfield2" /> </label> </p> <p> <label> <input type="text" name="textfield3" id="textfield3" /> </label> </p> <p> <label> <input type="Submit" name="button" id="button" value="Submit" onclick="resetForm()" /> </label> </p> <p> </p> </form> how do i reset first input box ..............other data should be remain as follows................ plz help me to do this Hello, The following web page is an essay, but there is JavaScript code in the head area: http://www.pinyinology.com/content/content3c.html You can see the 'Press F5 to reset' command, and please try it to see what happens. What I like is to create another command 'Click here to reset'. Therefore, there will be two commands for the reset task. Then it becomes: Click here or press F5 to reset. The press F5 stuff in the code is as follows; Code: //Typewriting code message='<span id="inTxt">wen<sup>2</sup></span>'; pos=0; maxlength=message.length+1; function writemsg() { if (pos<maxlength) { txt=message.substring(pos,0); document.getElementById('edit').innerHTML=txt; pos++; timer=setTimeout('writemsg()', 20); } } //Typewriting code2 own addition message2='<span id="inTxt2">wen<sup>2</sup>闻. ven<sup>2</sup>:文纹. win<sup>2</sup>:蚊. vin<sup>2</sup>:雯.'; pos=0; maxlength=message2.length+1; function writemsg2() { if (pos<maxlength) { txt=message2.substring(pos,0); document.getElementById('listing').innerHTML=txt; pos++; timer=setTimeout('writemsg2()', 20); } } Below is the complete code. It may help. Code: function KeyDown() { var key=window.event.keyCode; if (key==8) { window.event.returnValue=false; var r=document.selection.createRange(); r.collapse(false); r.move("character",-1); r.collapse(false); var p=r.parentElement(); if (p.nodeName.toLowerCase()=="sup"){ p.outerHTML=""; return; } window.event.returnValue=true; } } function KeyPress() { var key=window.event.keyCode; window.event.returnValue=false; if (key>=48 && key<=57) { var r=document.selection.createRange(); r.collapse(false); var d=r.duplicate(); d.moveStart("character",-1); var c=d.text; var p=d.parentElement(); var b=/[A-Za-z]/.test(c); //b=b || p.nodeName.toLowerCase()=="sup"; if (b) { d.collapse(false); var s=String.fromCharCode(key); s=(p.nodeName.toLowerCase()=="sup")? s:"<SUP>"+s+"</SUP>"; d.pasteHTML(s); d.collapse(false); d.select(); return; } } if (!(key in {37:1,38:1,39:1,40:1})) { var r=document.selection.createRange(); r.collapse(false); p=r.parentElement(); if (p.nodeName.toLowerCase()=="sup") { var s=p.outerHTML; p.removeNode(true); r.pasteHTML(s); r.collapse(false); r.select(); } } window.event.returnValue=true; } //Below for status line myMsg = " Happy Chinese typing !" var i = 0; function scrollMsg() { window.status = myMsg.substring(i,myMsg.length) + myMsg.substring(0,i); if (i < myMsg.length) { i++ } else { i = 0 } setTimeout("scrollMsg()",120) } function stoptimer() { clearTimeout(timer); } //Following function is for the appreciation window function newWindow() { catWindow = window.open('appr2.html', 'catwin','width=395,height=235, scrollbars=yes'); catWindow.focus(); } //Typewriting code message='<span id="inTxt">wen<sup>2</sup></span>'; pos=0; maxlength=message.length+1; function writemsg() { if (pos<maxlength) { txt=message.substring(pos,0); document.getElementById('edit').innerHTML=txt; pos++; timer=setTimeout('writemsg()', 20); } } //Typewriting code2 own addition message2='<span id="inTxt2">wen<sup>2</sup>闻. ven<sup>2</sup>:文纹. win<sup>2</sup>:蚊. vin<sup>2</sup>:雯.'; pos=0; maxlength=message2.length+1; function writemsg2() { if (pos<maxlength) { txt=message2.substring(pos,0); document.getElementById('listing').innerHTML=txt; pos++; timer=setTimeout('writemsg2()', 20); } } function stoptimer() { clearTimeout(timer); } Thanks in advance for your help. Hello guys I have a website which uses several forms to input data, each form contains fields for the user to complete and at the end of the each form the user has the option to proceed or go back. The problem is, on form1 there is a drop down box which determines the content of subsequent forms but when a user partially completes form2 but then goes back to form1 and changes the drop down box selection, the onchange function reloads the subsequent forms but it does not clear the previous form2 values so an error is generated because those inputs are not required with the change made to the drop down box. I have tried setting the ids to zero using getelementbyid on form1 but it does not seem to work presumably because the ids are on form2 not form1? Any thoughts would be much appreciated. Code: function my_fav_quote_show_optin_form() { if (!empty($_POST['my_fav_quote_email'])) { my_fav_quote_opt_in(); } $out2 = ''; $out = '<form action="" name="myform "method="post" id="requestQuote">'; $out .= '<table style="padding="0px" width="40px">'; $out .= '<tr><td>Name:*</td><td><input type="text" name="my_fav_quote_name" id="my_fav_quote_name"/></td></tr>'; $out .= ''; $out .= '<tr><td>Email:*</td><td><input type="text" name="my_fav_quote_email" id="my_fav_quote_email"/></td></tr>'; $out .= ''; $out .= '<tr><td>Phone:*</td><td><input type="text" name="my_fav_quote_phone" id="my_fav_quote_phone"/></td></tr>'; $out .= ''; $out .= '<tr><td>Event Date(optional):</td><td><input type="text" name="my_fav_quote_date" id="my_fav_quote_date"/></td></tr>'; $out .= ''; $out .= '<tr><td>Estimated Number of Guests(optional):</td><td><input type="text" name="my_fav_quote_guest" id="my_fav_quote_guest"/></td></tr>'; $out .= ''; $out .= '<tr><td>Desired Price Range Per Person (optional):</td><td><input type="text" name="my_fav_quote_rate" id="my_fav_quote_rate"/></td></tr>'; $out .= ''; $out .= '<tr><td style="vertical-align: middle;">Message:<br>(List your special requests, any food allergies , event description , special menu items that are not listed or any other information you think will helpful) </td><td><textarea placeholder="" name="my_fav_quote_message" id="my_fav_quote_message"></textarea></td></tr>'; $out .= ''; $out .= '<tr><td>Security code:*</td><td><img src='.get_bloginfo('wpurl').'/wp-content/plugins/quote-cart/captcha.php?width=60&height=30&characters=5" /></td></tr>'; $out .= ''; $out .= '<tr><td>Input Above Security Code He *</td><td><input type="text" name="security_code" id="security_code" size="5"></td></tr>'; $out .= ''; $out .='<tr><td colspan="2">'; if ( function_exists( 'my_fav_quote_display' ) ){ $out .= my_fav_quote_display(); } if ( function_exists( 'my_fav_quote_display3' ) ){ $out .= my_fav_quote_display3(); } $out .='</td></tr>'; $out .= '<tr><td colspan=2 align=center><input type="submit" value="Request Quote" onclick="return chk_validation()" style="background-color:#000;color:#FFF;padding:5px;margin-top:10px;border:none;cursor:pointer;"/> <input type="button" onclick="formReset()" value="Reset form" /> </td></tr>'; $out .='</table></form>'; echo $out; ?> <script language="javascript" type="text/javascript"> //<![CDATA[ function validate_email(field,alerttxt) { apos=field.indexOf("@"); // alert(apos); dotpos=field.lastIndexOf("."); //alert(dotpos); if (apos<1||dotpos-apos<2) { return false;} else {return true;} } function chk_validation() { if(document.getElementById("my_fav_quote_name") && document.getElementById("my_fav_quote_name").value == '') { alert("Please Enter Name"); document.getElementById("my_fav_quote_name").focus(); return false; } if(document.getElementById("my_fav_quote_email").value == '') { alert("Please Enter Email"); document.getElementById("my_fav_quote_email").focus(); return false; } else { //alert(validate_email(document.getElementById("my_fav_quote_email").value,"Not a valid e-mail address!"); if (validate_email(document.getElementById("my_fav_quote_email").value,"Please enter valid e-mail address!")==false) { alert("Please enter valid e-mail address!"); document.getElementById("my_fav_quote_email").focus(); return false; } } if(document.getElementById("security_code").value == '') { alert("Please Enter Security Code"); document.getElementById("security_code").focus(); return false; } if(document.getElementById("quotes").value == '') { alert("Please add atleast one request quote"); document.getElementById("quotes").focus(); return false; } //return true; } //]]> </script> <?php } can we reset the display functions data when we click on reset button? I am makeing a dice game and this is how i generate the numbers
Code: var randomnumber1=Math.floor(Math.random()*13) But i have to relaode the page each time to randomize it again. How can i do this with out reloading the page? I am using a button to set the function of. So I am working on a project that converts fahrenheit to celcius, or the other way around. So when I click on the radio button for fahrenheit to celcius, it disables the celcius textbox, and the celcius to fahrenheit radio button disables the fahrenheit text box. What I can't figure out is how to get my radio buttons to reset the form to be able to enter another conversion to be made. What it does is locks up both text boxes so that I can't enter anything at all after the first time I do it. Code: <body> <div id="content"> <h1>Convert temperature</h1> <input type="radio" onclick="reset();document.getElementById('degrees_celcius').disabled=this.checked" name="conversion_type" id="to_celcius" />From Fahrenheit to Celcius<br /> <input type="radio" onclick="reset();document.getElementById('degrees_fahrenheit').disabled=this.checked" name="conversion_type" id="to_fahrenheit" />From Celcius to Fahrenheit<br /> <br /> <form id="foofoo"> <label>Degrees Fahrenheit:</label> <input type="text" id="degrees_fahrenheit" class="disabled" /><br /> <label>Degrees Celcius:</label> <input type="text" id="degrees_celcius" class="disabled"/><br /> <br /> </form> <input type="button" id="convert" value="Convert" /><br /> <br /> </div> </body> Code: var temperature = function (){//This f if($("to_celcius").checked == true) { var far = parseFloat($("degrees_fahrenheit").value ); if(isNaN(far)) { alert("Please enter a valid temperature.") return; } var far_cel =Math.round((far-32) * 5/9); $("degrees_celcius").value = far_cel; }else ($("to_fahrenheit").checked ==true) { var cell = parseFloat($("degrees_celcius").value); if(isNaN(cell)) { alert("Please enter a valid temperature.") return; } var cel_far = Math.round(cell * 9/5 + 32); $("degrees_fahrenheit").value = cel_far; } } function reset()//resets the text box fields { $("foofoo").reset(); } window.onload = function(){ $("convert").onclick = temperature; $("to_fahrenheit").onclick = reset; $("to_celcius").onclick = reset; } hello everyone. I just joined this forum today, so I hope i'm not posting anything against the rules. if I am I will be more than happy to delete this thread. before I post my actual code can somebody please tell me if its okay to do so? the only reason I ask is because it is for a class project. I DID read the rules, but was still unsure if asking for help is okay or not. (because it is for an assignment) I don't want anybody to do the work for me, I just want to know if it is okay for me to ask for some assistance? any help with this would be greatly appreciated. Again, I hope I haven't broken any rules with this request.
How do I reset selct lists like below. <form> <select size='4' STYLE='width: 164px' MULTIPLE id="num" name='num[]'> <option value='1' selected>1</option> <option value='2' selected>2 </option> <option value='3' selected>3</option> </select> <input type="button" name="reset" > </form> http://www.masterclock.com/newContac...help/david.php I have a page with 3 forms. I've got javascript making them appear and disappear with buttons at the top. I mostly copied this guy's form: http://tetlaw.id.au/view/javascript/...eld-validation I added some conditional checkboxes using wform javascript library. my problem is that i need my reset button to a)reset the fields and b)re-hide the conditional fields. It works with the sales form and the catalog form (the catalog from doesn't use the conditional fields) but for some reason the request a quote form is convinced .request isn't a function. Even though it is using the same function as the sales form only it is pushing it's form id to it. what the heck am i doing wrong? And how awful and waste of space is my code? I have this code that when you click a button it will shuffle items in an array then you have 10 seconds to read it then the array items disappear. But I need to figure out how to make it so that you can do something like click another button that will allow you to click the twister drill button again and it will shuffle it heres the code any help would be appreciated Code: <script type="text/javascript"> function myFunction() { var myarray=["red","blue", "yellow", "orange"] myarray.sort(function() {return 0.5 - Math.random()}) var x=document.getElementById("demo"); x.innerHTML=myarray; } </script> <script type="text/javascript"> { var t=setTimeout("alertMsg()",10000); } function alertMsg() { document.getElementById("demo").style.display="none"; } </script> <button onclick="myFunction()">Twister Drill</button> <font size="5"> <p id="demo"></p> </font> One my website its one index page, putting in content depending on the link (ie ?page=xxxxx) and from that it generats the page name, (Page name - MySite). I also have an AJAX search form working on keyup (kinda like google autosearch). I want it so when i start typing there it changes the title to Search - MySite. Then when its empty revert to what ever it was before. Could someone gimmie a hand doing this? I already have the AJAX coding for the search bar so i can post that if iy would help more. EDIT: Also i need to check if its on the homepage or not, and if not load the homepage (currently done by php include), does javascript have an equivelant of php's include? Using the following script: <script language="JavaScript">TargetDate = "01/22/2010 7:50 AM UTC-0500"; BackColor = "palegreen"; ForeColor = "navy"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; FinishMessage = "Call In Now!!! Lines Are Open" </script> Want target date to equal every day so it resets after the target date and time is hit. Optionally, it would be nice to have it reset 60 minutes after target is hit (so the FinishMessage can display) but if that's too complicated, I'd be happy to not have to manually reset the date every day. I apologize in advance for being a newbie and this may be a straight-forward and simple issue. I have a number picker that works fine BUT when I reset the fields to enter another number, the start button will not work. I had to make it so the page reloads in order for the start button to work. This not only makes the site look worse than it already does but it's annoying to wait for the page to reload. I'd like to get all these bugs worked out and work on the site appearance after. Am I stuck with this reload thing or does someone know how I can fix it? Here's a link....http://www.psychiclotto.org/ Hi, I need a button that not only resets what is typed in the textarea but also hides all shown tables... Here's how my current set up is... ---------text area------ with a reset button table1 title (when clicked, shows a table under it) table2 title (when clicked, shows a table under it) table3 title (when clicked, shows a table under it) the tables under the main tables have buttons that when clicked on inserts texts in the textarea. Any help would be much much appreciated! how can set focus on Drop down after page is reset . when i press down key first time its working fine and select value but when i press again down key its focus out from drop down when i hard code means i give the control name its working fine but when i checking the type document.getElementById(document.activeElement.id).type == "select-one" its getting focus out after second time pressing down key sample code if (document.getElementById('control name'!=null) { document.getElementById('control name).focus(); if (document.getElementById(''control name)[document.getElementById('cntrlname').selectedIndex+1] !== null) { document.getElementById('cntrlname').selectedIndex=document.getElementById('cntrl namer').selectedIndex+1; document.getElementById('ctr name').onchange(); document.getElementById("ctlr name").selectedIndex = document.getElementById("ctr name").selectedIndex; document.getElementById('cntrl').focus(); } return false; } This code is working fine but this is spcefic to the control i want all drop down control in my app are set by pressing |