|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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();" > |
|
#3
|
|||
|
|||
|
Quote:
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. |
|
#4
|
||||
|
||||
|
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++) { ... |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Calling a JS functrion from within a JS function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|