Using Checkbox
Moderator: General Moderators
- Love_Daddy
- Forum Commoner
- Posts: 61
- Joined: Wed Jul 10, 2002 6:55 am
- Location: South Africa
- Contact:
Using Checkbox
Hi All,
Can anyone show me how to write a simple script to do the ff:
Say you have 3 check boxes with options to choose and 1 text box
Everytime you click on a checkbox, it writes your option inside the textbox and even if you uncheck.
Thanks.
Can anyone show me how to write a simple script to do the ff:
Say you have 3 check boxes with options to choose and 1 text box
Everytime you click on a checkbox, it writes your option inside the textbox and even if you uncheck.
Thanks.
- Johnm
- Forum Contributor
- Posts: 344
- Joined: Mon May 13, 2002 12:05 pm
- Location: Michigan, USA
- Contact:
This does what you want it to but it will need some editing as it is a stand alone page as written.
Direwolf
Direwolf
Code: Select all
<html>
<body>
<form>
<input type="checkbox" name="box1"
onClick="changeTextBox(this.form, 'newValue')"> Box 1
<input type="checkbox" name="box1"
onClick="changeTextBox(this.form, 'newValue2')"> Box 2
<input type="checkbox" name="box1"
onClick="changeTextBox(this.form, 'newValue3')"> Box 3
<input type="text" name="text_box" value="">
<script>
// Function to change text box
function changeTextBox(form, newValue)
{
form.text_box.value = newValue;
}
</script>
</form>
</body>- Love_Daddy
- Forum Commoner
- Posts: 61
- Joined: Wed Jul 10, 2002 6:55 am
- Location: South Africa
- Contact:
Thanks
Thanks for your input. 
Code: Select all
<html>
<head>
<script language="Javascript" type="text/javascript">
<!--
function changeTextBox(form, newValue)
{
form.text_box.value = newValue;
}
//-->
</script>
</head>
<body>
<form>
<input type="checkbox" name="box1"
onClick="changeTextBox(this.form, 'newValue')"> Box 1
<input type="checkbox" name="box1"
onClick="changeTextBox(this.form, 'newValue2')"> Box 2
<input type="checkbox" name="box1"
onClick="changeTextBox(this.form, 'newValue3')"> Box 3
<input type="text" name="text_box" value="">
</form>
</body>Code: Select all
function changeTextBox(form, newValue)
{
form.text_box.value = newValue;
}
THE ACTUAL PAGE- Love_Daddy
- Forum Commoner
- Posts: 61
- Joined: Wed Jul 10, 2002 6:55 am
- Location: South Africa
- Contact:
Thanks
Takuma,
Thanks for your reply, though this script does not work, I'll try and change here and there and will
let you know as soon as it's working!
Thanks
Thanks for your reply, though this script does not work, I'll try and change here and there and will
let you know as soon as it's working!
Thanks
- Johnm
- Forum Contributor
- Posts: 344
- Joined: Mon May 13, 2002 12:05 pm
- Location: Michigan, USA
- Contact:
Although Takuma's input refers mainly to personal preference and style both of these scripts (mine and his) work properly as I have tested them. The only thing I can see that needs to be changed is that each check box needs a different name. Right now all three are named "Box1". That won't keep the script from working though. Do you have JavaScript enabled on the browser you are testing this on?
Direwolf
Direwolf
- Love_Daddy
- Forum Commoner
- Posts: 61
- Joined: Wed Jul 10, 2002 6:55 am
- Location: South Africa
- Contact:
Javascript Browser
Well, I'm using Konqueror since I'm on Mandrake Linux.
I'll try to run the script on Internet Explorer.
And will let you know.
I'll try to run the script on Internet Explorer.
And will let you know.
- Love_Daddy
- Forum Commoner
- Posts: 61
- Joined: Wed Jul 10, 2002 6:55 am
- Location: South Africa
- Contact:
Checked
I ran the script on internet explorer and it works fine.
So I suppose on Konqueror, it doesn't work.
So what I need to do now is the following:
Everytime you choose an option, it must appear in the textbox and likewise
when you uncheck, it must disappear.
and if you choose all the options, they must all appear in the textbox.
The same, when you uncheck all, the textbox must be empty.
Thanksundefined