SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 8th, 2005, 02:43 PM
bibble bibble is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 2 bibble User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 6 m 37 sec
Reputation Power: 0
Calling a JS functrion from within a JS function

I have two JS functions that perform different tasks - I need to be able to call one from within the other using an "onclick".

Can this be done and if so, how???

Cheers for any help

Reply With Quote
  #2  
Old August 8th, 2005, 03:41 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 542 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 2 h 49 m 17 sec
Reputation Power: 3
calling functions

One javascript function can call another, simply put a line in the other script eg.
<script ....
function One() {
....
}

function Two() {
....
One();
...
}
</script>
You can call function Two from an onclick event
<input/a/etc.. onclick="Two();" >

Reply With Quote
  #3  
Old August 8th, 2005, 04:23 PM
bibble bibble is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 2 bibble User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 6 m 37 sec
Reputation Power: 0
Quote:
Originally Posted by Mittineague
One javascript function can call another, simply put a line in the other script eg.
<script ....
function One() {
....
}

function Two() {
....
One();
...
}
</script>
You can call function Two from an onclick event
<input/a/etc.. onclick="Two();" >

I have probably not explained myself properly!!

I'll list the code I'm having issues with.......

Firstly, I have this function........

function exclude(opt,q) {
opt=opt-1;
obj=eval("document.PdcSurvey.QQ8_A_" + q + "[" + opt + "]");
value=obj.value;
for (reset=1; reset<=5; ++reset) {
if (reset!=q) {
objReset=eval("document.PdcSurvey.QQ8_A_" + reset);
for (i=0; i<objReset.length; ++i) {
if (objReset[i].value==value) {
objReset[i].checked=false;
}
}
}
}
}

this "turns off" a radio button in a table column if the same row button is clicked.

The table rows themselves are randomised with an array function.......

<script type="text/javascript" language="JavaScript1.3"><!--
var RowList = new Array('<tr align="center" id="QQ8T1"><td nowrap="nowrap" align="left"><font style=\"font-size:10pt;\">Going on 1 holiday abroad per year</font></td><td><input type="radio" name="QQ8_A_1" value="1" id="QQ8_A_1_1" onclick="exclude(1,1)"></td><td><input type="radio" name="QQ8_A_2" value="1" id="QQ8_A_1_2" onclick="exclude(1,2)"></td><td><input type="radio" name="QQ8_A_3" value="1" id="QQ8_A_1_3" onclick="exclude(1,3)"></td><td><input type="radio" name="QQ8_A_4" value="1" id="QQ8_A_1_4" onclick="exclude(1,4)"></td><td><input type="radio" name="QQ8_A_5" value="1" id="QQ8_A_1_5" onclick="exclude(1,5)"></td></tr>','<tr align="center" id="QQ8T2"><td nowrap="nowrap" align="left"><font style=\"font-size:10pt;\">2 or more holidays abroad each year</font></td><td><input type="radio" name="QQ8_A_1" value="2" id="QQ8_A_2_1" onclick="exclude(2,1)"/></td><td><input type="radio" name="QQ8_A_2" value="2" id="QQ8_A_2_2" onclick="exclude(2,2)"/></td><td><input type="radio" name="QQ8_A_3" value="2" id="QQ8_A_2_3" onclick="exclude(2,3)"/></td><td><input type="radio" name="QQ8_A_4" value="2" id="QQ8_A_2_4" onclick="exclude(2,4)"/></td><td><input type="radio" name="QQ8_A_5" value="2" id="QQ8_A_2_5" onclick="exclude(2,5)"/></td></tr>','<tr align="center" id="QQ8T3"><td nowrap="nowrap" align="left"><font style=\"font-size:10pt;\">1 or more holidays in the UK</font></td><td><input type="radio" name="QQ8_A_1" value="3" id="QQ8_A_3_1" onclick="exclude(3,1)"/></td><td><input type="radio" name="QQ8_A_2" value="3" id="QQ8_A_3_2" onclick="exclude(3,2)"/></td><td><input type="radio" name="QQ8_A_3" value="3" id="QQ8_A_3_3" onclick="exclude(3,3)"/></td><td><input type="radio" name="QQ8_A_4" value="3" id="QQ8_A_3_4" onclick="exclude(3,4)"/></td><td><input type="radio" name="QQ8_A_5" value="3" id="QQ8_A_3_5" onclick="exclude(3,5)"/></td></tr>','<tr align="center" id="QQ8T4"><td nowrap="nowrap" align="left"><font style=\"font-size:10pt;\">Short Break holiday abroad</font></td><td><input type="radio" name="QQ8_A_1" value="4" id="QQ8_A_4_1" onclick="exclude(4,1)"/></td><td><input type="radio" name="QQ8_A_2" value="4" id="QQ8_A_4_2" onclick="exclude(4,2)"/></td><td><input type="radio" name="QQ8_A_3" value="4" id="QQ8_A_4_3" onclick="exclude(4,3)"/></td><td><input type="radio" name="QQ8_A_4" value="4" id="QQ8_A_4_4" onclick="exclude(4,4)"/></td><td><input type="radio" name="QQ8_A_5" value="4" id="QQ8_A_4_5" onclick="exclude(4,5)"/></td></tr>','<tr align="center" id="QQ8T5"><td nowrap="nowrap" align="left"><font style=\"font-size:10pt;\">Short Break holiday in the UK</font></td><td><input type="radio" name="QQ8_A_1" value="5" id="QQ8_A_5_1" onclick="exclude(5,1)"/></td><td><input type="radio" name="QQ8_A_2" value="5" id="QQ8_A_5_2" onclick="exclude(5,2)"/></td><td><input type="radio" name="QQ8_A_3" value="5" id="QQ8_A_5_3" onclick="exclude(5,3)"/></td><td><input type="radio" name="QQ8_A_4" value="5" id="QQ8_A_5_4" onclick="exclude(5,4)"/></td><td><input type="radio" name="QQ8_A_5" value="5" id="QQ8_A_5_5" onclick="exclude(5,5)"/></td></tr>','<tr align="center" id="QQ8T6"><td nowrap="nowrap" align="left"><font style=\"font-size:10pt;\">Visiting attractions in the UK <br>(Theme Park/Animal/Gallery/Museum/<br>Castle/Historic House)</font></td><td><input type="radio" name="QQ8_A_1" value="6" id="QQ8_A_6_1" onclick="exclude(6,1)"/> etc etc etc
<td><input type="radio" name="QQ8_A_5" value="17" id="QQ8_A_17_5" onclick="exclude(17,5)"/></td></tr>')
PdcShuffleArray(RowList);
for (var i=0;i<RowList.length;i++) {
document.write(RowList[i]);
}

and within the above code is an onclick event calling the "exclude" function.

It's this exclude function that doesn't appear to be working - the randomisation array is fine.

Reply With Quote
  #4  
Old August 9th, 2005, 09:01 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 542 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 2 h 49 m 17 sec
Reputation Power: 3
broken function

I have never seen for loops written this way
...
for (reset=1; reset<=5; ++reset) {
...
for (i=0; i<objReset.length; ++i) {
...
Would it work if they were changed to
...
for (reset=1; reset<=5; reset++) {
...
for (i=0; i<objReset.length; i++) {
...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Calling a JS functrion from within a JS function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway