Click to See Complete Forum and Search --> : arrays in arguments


BuTcHoK
10-10-2003, 02:39 AM
hello again, i want to create a function using javascript, but i dont know how to deal with the arguments....below is my script, as you can see my function keeps repeating, how could i make only one function that would apply to different indexes...

[PHP]
<script >
function makeAble(x) {
document.getElementById("text["+x+"]").disabled=false;
}
function makeDisable(x) {
document.getElementById("text["+x+"]").disabled=true;
}
function makeAble1(y) {
document.getElementById("text["+y+"]").disabled=false;
}
function makeDisable1(y) {
document.getElementById("text["+y+"]").disabled=true;
}
</script>

<body>
<input name="text1[print $x?>]" type="text" id="text1[<? print $x?>]" value="" onClick="makeDisable(<? print $x?>)" onDblClick="makeAble(<? print $x?>)" >

<input name="text2[print $y?>]" type="text" id="text2[<? print $y?>]" value="" onClick="makeDisable1(<? print $y?>)" onDblClick="makeAble1(<? print $y?>)" >
</body.

Gollum
10-10-2003, 05:21 AM
This should do...

function makeAble(x, bAble)
{
document.getElementById("text["+x+"]").disabled=bAble;
}


then


<body>
<input name="text1[print $x?>]" type="text" id="text1[<? print $x?>]" value="" onClick="makeAble(<? print $x?>,false )" onDblClick="makeAble(<? print $x?>, true )" >

<input name="text2[print $y?>]" type="text" id="text2[<? print $y?>]" value="" onClick="makeAble(<? print $y?>, false)" onDblClick="makeAble(<? print $y?>, true )" >
</body>


It turns out your makeAble and makeAble1 functions were identical - except that you used y instead of x for the second one.

and you can combine makeAble and makeDisable into one by passing in a boolean argument.

BuTcHoK
10-12-2003, 08:18 PM
thanks for your reply, but i have an additional question...

[QUOTE]
code:--------------------------------------------------------------------------------
function makeAble(x, bAble)
{
document.getElementById("text["+x+"]").disabled=bAble;
}
--------------------------------------------------------------------------------

what if i'll use text1 and text2 on function makeAble aside from "text" only? Do i have to make a third argument? and how could i insert it in html?