Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Field Value limit i++
Old 06-03-2005, 06:40 AM Field Value limit i++
Novice Talker

Posts: 10
Trades: 0
Hi!

I have something I am trying to make, and would be happy if anyone could help me.

I need a text field that the user can edit not directly, but by clicking a button that for example adds one to the value. There should be a maximum value in the field, like 5.

It also would be nice if i could have radio buttons or somthing that could change that value, for example by making one button allow up to the number 5 in the value field and another button allow the value field to have numbers as large as 10.

I hope this isnt' impossible
oreoT is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-03-2005, 10:13 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
definitely not impossible

form
HTML Code:
<form id="countform" name="countform" value="0">
<input type="radio" id="limit" name="limit" value="5" checked="checked"/>Max 5
<input type="radio" id="limit" name="limit" value="10" />Max 10
<br />
<input type="text" id="count_value" name="count_value" value="0" onBlur="check()"/>
<br />

<input type="button" id="count_up" name="count_up" value="Up" onClick="adjust('up')"/>
<input type="button" id="count_down" name="count_down" value="Down" onClick="adjust('down')"/>

</form>
Code:
<script type="text/javascript">
function adjust(direct) {
// increment or decrement the form input
var curr_count = getCurrent();
var limit = setLimit();

if (direct == "up") {
curr_count = inc(curr_count);
}
if (direct == "down") {
curr_count = dec(curr_count);
}
setCurrent(curr_count);
}

function check() {
// check for value on exit 
var curr_count = getCurrent();
var limit = setLimit();
if (curr_count <= 0) {
setCurrent(0);
}
if (curr_count >= limit) {
setCurrent(limit);
}
}

function setLimit() {
// set the max number from the radio buttons
if (document.forms[0].limit[1].checked) {
	var limit = 10;
	} else {
	var limit = 5;
}
return limit;
}

function getCurrent() {
// get current value of text box
return document.forms[0].count_value.value;
}
function setCurrent(curr_count) {
// set new value of text box 
document.forms[0].count_value.value = curr_count ;
}
function inc(curr_count) {
// increment current count and check for max
curr_count = parseInt(curr_count)+1;
var limit = setLimit();
	if (curr_count >= limit) {
	curr_count = limit;
	}
return curr_count;
}
function dec(curr_count) {
// decrement current count and check for 0 
curr_count = parseInt(curr_count)-1;
	if (curr_count <= 0) {
	curr_count = 0;
	}
return curr_count;
}
</script>
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-03-2005, 10:52 AM Awesome!
Novice Talker

Posts: 10
Trades: 0
Thats fantastic. Thanks a lot.
I only need to change it a bit to make it exactly as I pictured it.

There should be a few texfields, lets say 4, and the sum of these fields should act as the one field in the code above.

There should be 3 radio buttons that each makes a different max value. If the max value is 5, the 4 fields combined should not be able to go higer than five.

U up to the challenge chrishirst?
oreoT is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Field Value limit i++
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11478 seconds with 12 queries