/    Sign up×
Community /Pin to ProfileBookmark

arrays in arguments

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…

[code=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.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@GollumOct 10.2003 — This should do...
<i>
</i>function makeAble(x, bAble)
{
document.getElementById("text["+x+"]").disabled=bAble;
}


then

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

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


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.
Copy linkTweet thisAlerts:
@BuTcHoKauthorOct 13.2003 — thanks for your reply, but i have an additional question...


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?
×

Success!

Help @BuTcHoK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...