Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Troulble with Function
Old 11-02-2005, 05:21 PM Troulble with Function
Junior Talker

Posts: 3
Trades: 0
Hello,

I'm having what I believe is a syntax error issue with a script I wrote:

Code:
function changeTitle(f) {
for (var i = 0; i < document.form_59_155.elements['property_'+f+].length; i++) 
{document.form_59_155.['property_'+f+][i].checked = false;}
}
I'm not sure the correct way to go about writing this function, can anyone help me?

Thanks in advance for the help!
tagger is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-02-2005, 05:55 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
You need something after "+f+" or just make it "+f" and "['property_'+f+][i]" isn't valid - too many brackets, what are you trying to do, so I can get a better idea...
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-02-2005, 06:44 PM
Junior Talker

Posts: 3
Trades: 0
it sorts through a list of radio buttons and unchecks them. However, to be more effecient I would like to use it in a function, since I have several different groups of radio buttons on one page.

For instance if I was going to uncheck one group of radio buttons I would do:

Code:
function changeTitle() {
for (var i = 0; i < document.form_59_155.property_80.length; i++) 
{document.form_59_155.property_80[i].checked = false;}
}
I would like to write a function for this. So basically where you see the number 80, I would like to have the abilitily to change this by calling a function. Hope this makes sense. Thanks for taking a look...
tagger is offline
Reply With Quote
View Public Profile
 
Old 11-02-2005, 10:36 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
This should be what you're looking for, you can use eval() to turn strings into javascript statements:

Code:
<html>
<head>
<script><!--
function resetRadio(radioName) {
	for (i = 0; i <= eval("document.form_59_155." + radioName + ".length")-1; i++) {
		eval("document.form_59_155." + radioName + "[" + i + "].checked = false");
	}
}
--></script>
</head>
<body>
<form name="form_59_155" onsubmit="changeTitle();">
<input type="button" value="Uncheck Alpha group" onclick="resetRadio('alpha');">
<input type="radio" name="alpha" value="blahe">
<input type="radio" name="alpha" value="asldkjas">
<input type="radio" name="alpha" value="askdjv">
<br>
<br>

<input type="button" value="Uncheck Beta group" onclick="resetRadio('beta');">
<input type="radio" name="beta" value="asdasfff">
<input type="radio" name="beta" value="qweqwe">
<input type="radio" name="beta" value="hgdfh">
<input type="radio" name="beta" value="uiopuip">
<input type="radio" name="beta" value="vsdfsf">
</form>

</body>
</html>

Last edited by funkdaddu; 11-02-2005 at 10:41 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-03-2005, 12:45 PM
Junior Talker

Posts: 3
Trades: 0
whew! Thanks a mil!
tagger is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Troulble with Function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18338 seconds with 12 queries