/    Sign up×
Community /Pin to ProfileBookmark

Fill input box and add text to the page

I know this is fairly simple, I haven’t been coding for awile and my mind won’t get around this.
I have a page where you can click “+” or “-” to edit the number in the input box. I need to show the total change of the number next to the box. For instance if the box has four and you click “+” then the box has 5 and a 1 next to it. I can’t put the 1 in an input box because it causes form problems with my script. I need to write the total adjustment number on the page.
Here is what I’m working with.

[code=php]function qty(obj, i)
{
obj = document.getElementById(obj);

if(typeof obj == ‘object’)
obj.value = parseInt(obj.value) + i;
obj.className == null;
obj.className == ‘hidemered’;
}
<input type=”button” name=”Submit” value=” + ” onclick=”qty(‘product1’, 1)”>
<input type=”button” name=”Submit” value=” – ” onclick=”qty(‘product1’, -1)”>[/code]

After that I need to write the total adjusted number. I tried a few things in the function qty, but I’m too rusty at it. Thanks for any help!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinFeb 25.2006 — obj.className == 'hidemered';

should be : obj.className = 'hidemered';

== is for testing

= is for setting

if the setting of the class is within the 'if' statement, you have multiple lines within that statement and therefore should have curly braces encompassing its child lines

if("I have more than 1 line" == true){

line 1;

line 2;

}

the total change is simply the number of times a button is clicked + or -

obj.value = parseInt(obj.value) + i;

obj2.value = parseInt(obj2.value) +i;

obj2 is simply starting from 0
×

Success!

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