/    Sign up×
Community /Pin to ProfileBookmark

help with passing a php array to javascript.

I have a form where the name of each input is part of a php array, with the first piece of code below for the input. What I’m trying to do is switch the cursor to the next input box after the user inputs the max size for the input. I’m having a problem with passing the name of the next input to the javascript function.

[CODE]for($count = 0; $count < 18; $count++) {
$next = $count+1;
echo “<td><input type=”text” size=”2″ name=”putts[$count]” onkeyup=”TabNext(this,’up’,1,this.form.putts[$next])” onkeydown=”TabNext(this,’down’,1)” maxlength=”1″ value=””.$card[“putts”][$count].””/></td>”;
}[/CODE]

Here is the javascript. I’m having problems with the next_field.focus() to go to the next input.

[CODE]var phone_field_length=0;
function TabNext(obj,event,len,next_field) {
if (event == “down”) {
phone_field_length=obj.value.length;
}
else if (event == “up”) {
if (obj.value.length != phone_field_length) {
phone_field_length=obj.value.length;
if (phone_field_length == len) {
next_field.focus();
}
}
}
}[/CODE]

obj : The input object (this)
event: Either ‘up’ or ‘down’ depending on the keypress event
len : Max length of field – tab when input reaches this length
next_field: input object to get focus after this one

Any help would be appreciated.
Thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@cgishackJan 09.2008 — Unless form.putts[$next] is an integer you have to have a single quotations around it.

Try adding escaped ' around this area
[CODE]
[B]this.form.putts[$next][/B]
[/CODE]



Drew
Copy linkTweet thisAlerts:
@ss1289authorJan 10.2008 — Unless form.putts[$next] is an integer you have to have a single quotations around it.

Try adding escaped ' around this area
[CODE]
[B]this.form.putts[$next][/B]
[/CODE]



Drew[/QUOTE]

form.putts[$next] is an integer. I still tried that and it didn't work.

Thanks for the reply though.
Copy linkTweet thisAlerts:
@cgishackJan 10.2008 — can you paste what the HTML output looks like of this string ?

<i>
</i>echo "&lt;td&gt;&lt;input type="text" size="2" name="putts[$count]" onkeyup="TabNext(this,'up',1,this.form.putts[$next])" onkeydown="TabNext(this,'down',1)" maxlength="1" value="".$card["putts"][$count].""/&gt;&lt;/td&gt;";


Drew
Copy linkTweet thisAlerts:
@ss1289authorJan 10.2008 — can you paste what the HTML output looks like of this string ?

<i>
</i>echo "&lt;td&gt;&lt;input type="text" size="2" name="putts[$count]" onkeyup="TabNext(this,'up',1,this.form.putts[$next])" onkeydown="TabNext(this,'down',1)" maxlength="1" value="".$card["putts"][$count].""/&gt;&lt;/td&gt;";


Drew[/QUOTE]

sure

[CODE]<input type="text" value="" maxlength="1" onkeydown="TabNext(this,'down',1)" onkeyup="TabNext(this,'up',1,this.form.putts[1])" onblur="addNumbers();" name="putts[0]" size="2"/>

<input type="text" value="" maxlength="1" onkeydown="TabNext(this,'down',1)" onkeyup="TabNext(this,'up',1,this.form.putts[2])" onblur="addNumbers();" name="putts[1]" size="2"/>[/CODE]
×

Success!

Help @ss1289 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...