473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

need help to clear textbox with unchecked checkbox

Hi there,
I would like to be able to clear the textbox when we uncheck the checkbox. Is that possible?

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3.   <head>
  4.     <title>cmene be fa no da pagbu</title>
  5.     <script type="text/javascript">
  6.       var Format = {
  7.         currency: function(n, dp, s) {
  8.           return (s || '€ ') + n.toFixed(dp || 2).replace(".",",");
  9.         },
  10.  
  11.         interpolate: function(s) {
  12.           for (var i = 1; i < arguments.length; ++i)
  13.             s = s.replace("%s", arguments[i]);
  14.  
  15.           return s;
  16.         }
  17.       };
  18.  
  19.       var Functional = {
  20.         map: function(f, a) {
  21.           for (var i = a.length - 1, r = []; i >= 0; --i)
  22.             r[i] = f(a[i], i);
  23.  
  24.           return r;
  25.         }
  26.       };
  27.  
  28.       var Dom = {
  29.         getElementsByClassName: (function() {
  30.           function getElementsByClassName_(root, className) {
  31.             return (className(root.className || "") ? [root] : []).concat(entr(root, className));
  32.           }
  33.  
  34.           function entr(root, className) {
  35.             if (typeof className === "string")
  36.               className = (function(cn) {
  37.                 return function(c) {
  38.                   return c.indexOf(cn) >= 0;
  39.                 };
  40.               })(className);
  41.  
  42.             return Array.prototype.concat.apply([], Functional.map(function(e) {
  43.               return getElementsByClassName_(e, className);
  44.             }, root.childNodes));
  45.           }
  46.  
  47.           return entr;
  48.         })()
  49.       };
  50.  
  51.       var TallyPage = {
  52.         sumForm: function(frm, qstr) {
  53.           for (var t = 0, v, e = Dom.getElementsByClassName(frm, "sum"), i = e.length; --i >= 0; )
  54.         if (e[i].type === "checkbox" && e[i].checked)    
  55.               t += ((v = frm.elements[Format.interpolate(qstr, e[i].name)]) ? v.value : 1) * parseFloat(e[i].value, 10);
  56.  
  57.           return t;
  58.         },
  59.  
  60.         updateForm: function(frm, out) {
  61.           (out.firstChild || out.appendChild(document.createTextNode(""))).nodeValue = Format.currency(TallyPage.sumForm(frm, "%s_q"));
  62.         },
  63.  
  64.         init: function() {
  65.           var ud = function() { TallyPage.updateForm(this.form, document.getElementById("output")); },
  66.               v;
  67.  
  68.           Functional.map(function(e) { e.onclick = e.onkeyup = e.onchange = ud; },
  69.               Dom.getElementsByClassName(v = document.forms['sum_form'], function(c) {
  70.                 return c.indexOf('sum') >= 0 || c.indexOf('quantity') >= 0;
  71.               }));
  72.  
  73.           TallyPage.updateForm(v, document.getElementById("output"));
  74.  
  75.           (v = v.elements.subm).parentNode.removeChild(v);
  76.           v = null;
  77.         }
  78.       };
  79.  
  80.       onload = TallyPage.init;
  81.     </script>
  82.   </head>
  83.   <body>
  84.     <form action="/some/summer" id="sum_form">
  85.  
  86.     <input type="checkbox" value="45.25" class="sum" name="101">
  87.     45,25€<input type="textbox" class="quantity" name="101_q" value="1">
  88.    <br> 
  89.     <input type="checkbox" value="50.75" class="sum" name="410">
  90.     50,75€<input type="textbox" class="quantity" name="410_q" value="1">
  91.  
  92.     <span id="output">&nbsp;</span>
  93.     <input name="subm" type="submit" value="Total">
  94.  
  95.  
  96.  
  97.     </form>
  98.   </body>
  99. </html>
Jun 12 '11 #1
1 4130
johny10151981
1,059 1GB
try this.
Expand|Select|Wrap|Line Numbers
  1. <input type=checkbox onclick='if(this.value==checked) docuement.getElementById("clear").value=""'>
  2. <input type=text id='clear'>
  3.  
Jun 13 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rodney King | last post by:
Hi, I have developed an ASP page which dynamically displays a list of checkbox options based on a SQL statement. Here is my code: <div style="OVERFLOW:auto; Height: 150px"> <table> <% dim...
3
by: Terence Parker | last post by:
I'm not sure whether this question demands a JavaScript answer or a simple HTML one - so apologies for the cross posting. I am grabbing a bunch of data from MySQL using PHP and returning the...
0
by: Henry | last post by:
How to know if a click is on a DataGridTextBoxColumn or DataGridBoolBoxColumn in a datagrid? How to use dataview.ListChanged event to catch the content change for a textbox and/or checkbox? ...
4
by: Patrick.O.Ige | last post by:
Whats the best way to clear textboxes? Any ideas?
2
by: magmo | last post by:
Hi I have a checkbox column in my datagrid. When I uncheck the checkbox it turn grey, and then I have to uncheck it once more to get it completly unchecked. Why is that? I would like to skip...
1
by: bird | last post by:
Greetings, I'm trying to calculate the total on an php page. I'm able to get the checkbox portion to work properly but I'm having trouble with the textbox "txtshipping". The default is 7.95...
2
by: g7murali123 | last post by:
hi, my textbox contains text as "search" on pageload when the user click the textbox the text "search" should disappear and the textbox must get the value of the user entering text. please help the...
1
by: rando1000 | last post by:
So I have this form that captures Me.CheckboxName.Value as part of an SQL statement. For one checkbox, it evaluates as 0, which is great, because I'm filling a Yes/No field with it. But for another...
6
by: beary | last post by:
This is embarrassing, but I have a form pulling data from mysql using php. Lots of different checkboxes in it. When user checks one or more boxes, all goes well; values are added and db is updated....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.