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

using javascript in the onchange event

Im trying to get a tick box to tick automatically when the user changes the
textfield called comm. my code is below but it doesnt work.
Can anyone see why?
function changed(x)
{
document.getElementById(x).checked;
}

<input name="changed" id="ischanged" type="checkbox" value="">

<textarea name="comm[]" rows="2" class="BodyText" style="WIDTH: 99%"
onChange="changed(ischanged)"><?php echo stripslashes($comment);
?></textarea>

thanks
Ian
Aug 7 '06 #1
4 4827
mantrid wrote on 07 aug 2006 in comp.lang.javascript:
Im trying to get a tick box to tick automatically when the user
changes the textfield called comm. my code is below but it doesnt
work. Can anyone see why?
function changed(x)
{
document.getElementById(x).checked;
}

<input name="changed" id="ischanged" type="checkbox" value="">

<textarea name="comm[]" rows="2" class="BodyText" style="WIDTH: 99%"
onChange="changed(ischanged)"><?php echo stripslashes($comment);
?></textarea>
onChange="changed('ischanged')"
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 7 '06 #2

Evertjan. wrote:
mantrid wrote on 07 aug 2006 in comp.lang.javascript:
Im trying to get a tick box to tick automatically when the user
changes the textfield called comm. my code is below but it doesnt
work. Can anyone see why?
function changed(x)
{
document.getElementById(x).checked;
That just returns the value of the checked property, it doesn't set it
to anything:

document.getElementById(x).checked = true;

}

<input name="changed" id="ischanged" type="checkbox" value="">

<textarea name="comm[]" rows="2" class="BodyText" style="WIDTH: 99%"
onChange="changed(ischanged)"><?php echo stripslashes($comment);
?></textarea>

onChange="changed('ischanged')"

--
Rob

Aug 7 '06 #3
Thanks to both of you
It now works with the two changes you suggested

"RobG" <rg***@iinet.net.auwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
Evertjan. wrote:
mantrid wrote on 07 aug 2006 in comp.lang.javascript:
Im trying to get a tick box to tick automatically when the user
changes the textfield called comm. my code is below but it doesnt
work. Can anyone see why?
>
>
function changed(x)
{
document.getElementById(x).checked;

That just returns the value of the checked property, it doesn't set it
to anything:

document.getElementById(x).checked = true;

>}
>
<input name="changed" id="ischanged" type="checkbox" value="">
>
<textarea name="comm[]" rows="2" class="BodyText" style="WIDTH: 99%"
onChange="changed(ischanged)"><?php echo stripslashes($comment);
?></textarea>
onChange="changed('ischanged')"


--
Rob

Aug 8 '06 #4
JRS: In article <tF*******************@newsfe4-gui.ntli.net>, dated
Mon, 7 Aug 2006 20:47:21 remote, seen in news:comp.lang.javascript,
mantrid <ia********@virgin.netposted :
>Im trying to get a tick box to tick automatically when the user changes the
textfield called comm. my code is below but it doesnt work.
Can anyone see why?
function changed(x)
{
You should put alert(999) here. Then you will discover whether your
function gets called. For me at least, it does. Therefore your error
must concern the following line :-
>document.getElementById(x).checked;
So change that, /pro tem/, to
var T = document.getElementById(x)
alert(typeof T)
T.checked;

and you should see that the value of T depends reasonably on whether you
give the name of the checkbox or a non-existent name. Then look up
<CHECKBOX>.checked and see that you are not using it appropriately.
>}

<input name="changed" id="ischanged" type="checkbox" value="">

<textarea name="comm[]" rows="2" class="BodyText" style="WIDTH: 99%"
onChange="changed(ischanged)"><?php echo stripslashes($comment);
?></textarea>
It's not a good ides to have a function with the same name as a control.
Even if the browser is not confused, some reader may be.
Read the newsgroup FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joe Kelsey | last post by:
When you use addEventListener (or addEvent in IE) to call an object method, does it call it with the correct this parameter? The ECMAScript reference has a lot to say about the caller using...
1
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping...
14
by: horos | last post by:
hey all, I'm a heavy perl user, not so much a java script user, and was wondering... perl has an extremely nice utility called Data::Dumper, which allows you to dump out the contents of an...
2
by: Luis Esteban Valencia Muñoz | last post by:
I have a datagrid that displays editable text fields (2 different price fields) and a checkbox in every row. It has a "SaveChanges" button at the bottom, which, when pressed, looks at every...
4
by: Shawn Repphan | last post by:
I apoligize if this is out of scope with this group. I have a textbox that displays a current record number(xx of xxx). The user has the ability to enter their own number into this box and perform...
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
4
by: mantrid | last post by:
Can anyone see why the checkbox in the code below doesnt get ticked when the textbox is changed ***This javascript function is called in the textbox's onchange event to check it when it is...
3
by: itp | last post by:
I have moved to Matt Kruse's Javascript Toolbox. It has some great examples to get you going quickly! Unfortunately all the examples are based on a form/submit model. I would like to try using...
4
by: auslandt | last post by:
I have an HTML file that includes a JavaScript. I would like this JavaScript to be able to create an "onChange=<function>" attribute against the password element. Here is an example page of the...
13
by: DDragon | last post by:
ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.