/    Sign up×
Community /Pin to ProfileBookmark

Can’t get a form object name to concatenate!

I am having a very hard time with some seemingly simple code.

My code:

[CODE]function UpdatePrice(BBID) { // v1.0
document.Edit.eval(‘Price’+BBID).value = (document.Edit.eval(‘DPrice’+BBID).value) * (1 + (document.Edit.eval(‘Markup’+BBID).value) / 100);
}

function UpdateMarkup(BBID) { // v1.0
document.Edit.Markup[‘+BBID+’].value = (((document.Edit.Price[‘+BBID+’].value / document.Edit.DPrice[‘+BBID+’].value) – 1) * 100);
}[/CODE]

Page to see the errors:
[url]http://build.contenderbicycles.com/admin/edit_bb.asp[/url]

Enter a price in DPrice and then input a Margin and it is supposed to calculate the Price. Or enter a DPrice and Price and it should calculate the Margin.

Travis Cable

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonMay 25.2004 — The script takes the values from text input fileds, these values are strings and to preform the calculations they need to be numbers, try this code:function UpdatePrice(BBID) { // v1.0
document.Edit.eval('Price'+BBID).value = (parseInt(document.Edit.eval('DPrice'+BBID).value)) * (1 + (parseInt(document.Edit.eval('Markup'+BBID).value)) / 100);
}

function UpdateMarkup(BBID) { // v1.0
document.Edit.Markup['+BBID+'].value = (((parseInt(document.Edit.Price['+BBID+'].value) / parseInt(document.Edit.DPrice['+BBID+'].value)) - 1) * 100);
}
I've not looked over your code properly so there may be other errors, with any luck there won't be though. ?
Copy linkTweet thisAlerts:
@tlcable7authorMay 25.2004 — Thanks for your help, but do you mind taking another look? I am getting a new error.

When calling the function, is it proper to call it like this, UpdatePrice(ID), or with quotes, UpdatePrice("ID")?

Travis
Copy linkTweet thisAlerts:
@FangMay 25.2004 — Both can be correct.

The first one is passing a variable, the second passes a string.
Copy linkTweet thisAlerts:
@tlcable7authorMay 25.2004 — Will you take a look at the error it's giving? It still won't work!

Travis
Copy linkTweet thisAlerts:
@David_HarrisonMay 25.2004 — My guess is that you're still getting errors because you're still trying to do maths with strings.

I also have no idea what this is supposed to mean:

document.Edit.Price["'+BBID+'"]

I think that your best bet would be to give every input a unique systematic name, take each column heading and add a number for the row that a particular field is on. You should be able to do that easy because you're using ASP to generate the page.

I have no idea what the script is supposed to do though, it obviously isn't working but I get no error.

I suggest that you explain very carefully exactly how to use this form and what it is supposed to do.
×

Success!

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