/    Sign up×
Community /Pin to ProfileBookmark

Need Help with an Array

Hello everyone ?

Hope everyone is well. I’m new to JavaScript and would love some help here.

I’m just trying to learn it as much as i can but i’m having a problem with something was hoping someone would be able to help me

what i’m hoping to have is a text box and beside that box there are 2 images (of arrows) one up and one down.

what i want is when the user clicks the up arrow the text box will dispay the number 1 and if clicked again the number is 2 and etc etc and when they click down well the number goes down but i want a limit on the number i’m hoping to have 0-50.

does anyone have anyideas

Thanks So Much ?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@CharlesMay 13.2003 — [font=georgia]These are for demonstration purposes only, but they should give you a few ideas.[/font]

[font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<form action="" onsubmit="return false">

<div>

<input type="text" value="1"><br>

<button onclick="if (document.forms[0].elements[0].value < 50) document.forms[0].elements[0].value++">Increment</button>

<button onclick="if (document.forms[0].elements[0].value > 0)document.forms[0].elements[0].value--">Decrement</button>

</div>

</form>

<p id="number">1</p>

<button onclick="if (document.getElementById('number').innerHTML < 50) document.getElementById('number').innerHTML++">Increment</button>

<button onclick="if (document.getElementById('number').innerHTML > 0) document.getElementById('number').innerHTML--">Decrement</button>[/font]
Copy linkTweet thisAlerts:
@RedheadauthorMay 14.2003 — Both examples are amazing i would not have even thought there would be so many was of doing that.

but what about when it becomes a form and you need to have more then one on it.

below is the example from Dave Clark, i added another text field in to see how that worked and guess what it does not i keep getting errors.

<table border="0" cellspacing="0" cellpadding="0">

<tr>

<td rowspan="2">

<form>

<input value="1" type="text" name="T1">

</form></td>

<td valign="bottom"> <img src="images/up.jpg" width="50" height="50" onclick="return sumIt(document.forms[0].T1, +1);"></td>

</tr>

<tr>

<td valign="top"> <img src="images/down.jpg" width="50" height="50" onclick="return sumIt(document.forms[0].T1, -1);">

</td>

</tr>

<tr>

<td rowspan="2">

<input value="1" type="text" name="T2">
</td>
<td valign="bottom"> <img src="images/up.jpg" width="50" height="50" onclick="return sumIt(document.forms[0].elements[0].T2, +1);"></td>

</tr>

<tr>

<td valign="top"> <img src="images/down.jpg" width="50" height="50" onclick="return sumIt(document.forms[0].elements[0].T2, -1);">

</td>

</tr>

</table>

<script language="javascript" type="text/javascript">

<!--//

function sumIt(fld, val) {

var nbr = Number(fld.value);

nbr = (isNaN(nbr)) ? 0 : nbr;

nbr += val;

nbr = (nbr < 0) ? 0 : nbr;

nbr = (nbr > 50) ? 50 : nbr;

fld.value = nbr;

return true;

}

</script>

would you have any more ideas
Copy linkTweet thisAlerts:
@RedheadauthorMay 14.2003 — Hi All

I guess my main goal is to see if it is possible to have a text box with 2 arrow beside it on up and one down to sort thourght and array?

Any thoughts?


Thanks Redhead ?
Copy linkTweet thisAlerts:
@CharlesMay 14.2003 — [font=georgia]I'm sorry but I do not understand what it is that you want and what an array has to do with it.[/font]
Copy linkTweet thisAlerts:
@RedheadauthorMay 14.2003 — What i'm hoping to have is a page where there are 3 text box's apart of a form.

Text box one for the day of the week, another for the month, and another for the year.

beside each text box is images of arrows one up and one down.

when the user clicks on the arrow beside the day text box the day of the week goes up 1,2,3,4, etc etc. and when they click the down arrow they see 4,3,2,1, etc etc.

the same goes for the month and the year

the following scirpt works for a text box but i can seem to add more,

but would there not be a way to sort an array? like a list of the months and years? what are your thoughts thanks so much

<body>

<table border="0" cellspacing="0" cellpadding="0">

<tr>

<td rowspan="2">

<form>

<input value="1" type="text" name="T1">

</form></td>

<td valign="bottom"> <img src="images/up.jpg" width="50" height="50" onclick="return sumIt(document.forms[0].T1, +1);"></td>

</tr>

<tr>

<td valign="top"> <img src="images/down.jpg" width="50" height="50" onclick="return sumIt(document.forms[0].T1, -1);">

</td>

</tr>

</table>

<script language="javascript" type="text/javascript">

<!--//

function sumIt(fld, val) {

var nbr = Number(fld.value);

nbr = (isNaN(nbr)) ? 0 : nbr;

nbr += val;

nbr = (nbr < 0) ? 0 : nbr;

nbr = (nbr > 50) ? 50 : nbr;

fld.value = nbr;

return true;

}

//-->

</script>
Copy linkTweet thisAlerts:
@RedheadauthorMay 15.2003 — That is so cool thanks so much

using the same idea with a text box and the arrows up and down how would you sort thrugh an arrary of months for an example

Redhead ?
Copy linkTweet thisAlerts:
@RedheadauthorMay 15.2003 — Hi Again

Talk about being a bug. I'm going to try and explan my goal here.

Ok you have a page, on that page you see 3 text boxes and beside each text box you see 2 arrows on up and one down.

If you clicked on the fist arrow you would see the number go up if you clicked down you would see it go down,

that's the same for text box 2, but text box 3 displays the years.

The main idea that i have is to use the arrrows (up or down) to allow the user to select a date.

day, month, year, i'm hoping to use number.

I think i might want a new Hobbie LOL, sorry about all the confusion i'm learning here and doing my best. I like to make up problems or ideas and try and do them to see how or if it can be done.

Thanks for all your help

Redhead ?
×

Success!

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