473,378 Members | 1,110 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,378 software developers and data experts.

auto-populate textbox

Hi,

I have an html page that has both a textbox and a checkbox.
I need to autopopulate the textbox with a value of "0" when the checkbox is selected.

I am not sure which JS function to use.

Thaks in advance for your help. :-)

marcelo
Oct 25 '07 #1
6 2296
I shall be your savior :)
Well, if the effect your looking for is just when it's selected, and does not remove the 0 from the textbox when you check the checkbox, you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.  var oCheckbox = document.getElementById('id of checkbox');
  3.  oCheckbox.onclick = function() {
  4.   document.getElementById('id of textbox').value = '0';
  5.  }
  6. }
  7.  
I could use DOM 2 event listeners, but this seems like a rather simple application so I'll leave it at that. Just reply if you wanted "0" to go away when you un-select the checkbox...
And WHY does the stupid thing say I'm a newbie? I don't know.
Oct 25 '07 #2
acoder
16,027 Expert Mod 8TB
And WHY does the stupid thing say I'm a newbie? I don't know.
Get to 32 posts and it'll go away :)
Oct 26 '07 #3
Get to 32 posts and it'll go away :)
Oh okay that's easy :) I thought it was measured by how long you've been registered.
Oct 26 '07 #4
I shall be your savior :)
Well, if the effect your looking for is just when it's selected, and does not remove the 0 from the textbox when you check the checkbox, you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.  var oCheckbox = document.getElementById('id of checkbox');
  3.  oCheckbox.onclick = function() {
  4.   document.getElementById('id of textbox').value = '0';
  5.  }
  6. }
  7.  
I could use DOM 2 event listeners, but this seems like a rather simple application so I'll leave it at that. Just reply if you wanted "0" to go away when you un-select the checkbox...
And WHY does the stupid thing say I'm a newbie? I don't know.

I actually do need the "0" to go away when the checkbox is unchecked.
Thank you so much for your reply.
You are really are my savior :-)
Oct 26 '07 #5
Okay then, here's the code to do that.
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.     var oCheckbox = document.getElementById('id of checkbox');
  3.     var oTextbox = document.getElementById('id of textbox');
  4.     oCheckbox.onclick = function() {
  5.         if(this.checked) {
  6.             oTextbox.value = '0';
  7.         }
  8.         else {
  9.             oTextbox.value = '';
  10.         }
  11.     }
  12. }
I'm not sure if you were accepting input from users in the textbox, but I'll make a script so that if they un-check and then re-check the box their entered value is saved... So there ya go :)
Oct 28 '07 #6
Thank you very much!!!
Oct 30 '07 #7

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

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
2
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.