/    Sign up×
Community /Pin to ProfileBookmark

New Variable problem

lol I asked the wrong question in my last post…lol
Here is what I’m really looking for:

[CODE] function checkbox(i) {
var time = new Date();
var hours = time.getHours();
var minutes = time.getMinutes();

if (document.form.check_i.checked == true) {
document.form.text_i.value = hours + “:” + minutes;
} else if (document.form.check_i.checked == false) {
document.form.text_i.value = “”;
}
}[/CODE]

You can see text_i and check_i. I need the ‘i’s to be replaced with the value of ‘i’. Is there a way to do that?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@BuilderQOct 28.2006 — You could try using the elements array, which allows you to refer to each input in a form based on how many preceded it. For example, if i starts at 1, there are no other elements in the form aside from the textboxes and checkboxes, and the form itself is named "form", this function would work:
[code=php]
function checkbox(i) {
var time = new Date();
var hours = time.getHours();
var minutes = time.getMinutes();

if (document.form.elements[i*2-1].checked == true) {
document.form.elements[i*2-2].value = hours + ":" + minutes;
} else if (document.form.elements[i*2-1].checked == false) {
document.form.elements[i*2-2].value = "";
}
}
[/code]
Copy linkTweet thisAlerts:
@maiku_no_jutsuauthorOct 28.2006 — okies, i was using getElementbyID at one point, thinking it did what element did....but then i found out it wasnt and was back to square one...i was close, but not close enough, thanks
Copy linkTweet thisAlerts:
@NaldzOct 29.2006 — instead of using the dot notation:
[CODE]
document.form.text_i.value;
[/CODE]

you can also refer to elements this way:
[CODE]
document.form['text_'+i].value;
[/CODE]
Copy linkTweet thisAlerts:
@KorOct 30.2006 — or even better:
<i>
</i>document.forms['form'].elements['text_'+i].value
×

Success!

Help @maiku_no_jutsu 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,
)...