Click to See Complete Forum and Search --> : Need Help with an Array


Redhead
05-13-2003, 05:17 PM
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 :)

Charles
05-13-2003, 05:43 PM
These are for demonstration purposes only, but they should give you a few ideas.

<!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>

khalidali63
05-13-2003, 06:18 PM
Check this link out..
http://68.145.35.86/skills/javascripts/ClickCounter.html

Redhead
05-14-2003, 10:13 AM
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

Redhead
05-14-2003, 10:54 AM
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 :confused:

Charles
05-14-2003, 11:55 AM
I'm sorry but I do not understand what it is that you want and what an array has to do with it.

Redhead
05-14-2003, 12:01 PM
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>

Redhead
05-14-2003, 07:34 PM
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 :D

Redhead
05-15-2003, 09:42 AM
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 :)