/    Sign up×
Community /Pin to ProfileBookmark

form validation help!

My client is a complete novice when it comes to web technology, so Im trying to validate as much as possible with this form (using javascript) before it gets submitted in the database.

I have two problems on hand:

1) I am trying to validate it so that the value for Volume5a is equal to the the last volume that has been selected.

This means that value for Volume5a may equal to Volume4b or Volume3b or Volume2b or Volume1b. The problem is the client may use up to 5 different volumes, but he doesnt have to. So he can use 4 or 3 or 2 different volumes if he wishes to – depending on his products and their volume prices.

2) The volumes quantities must be correct. So if volume 1 and 2 were selected, Volume2a must equal to Volume1b + 1. If volume 2 and 3 were selected, Volume3a must equal to Volume2b + 1….. and so forth.

Again, not all 5 volumes have to be used.

Heres my form! (or alternatively: [url]http://members.iinet.net.au/~hinda/js/form.htm[/url])

function validateform(){
var aSetPrice = document.form1.SetPrice.value;
var SPT = document.form1.SetorVolumePrice;
var V5 = document.form1.VolumeTick5;
var V4 = document.form1.VolumeTick4;
var V3 = document.form1.VolumeTick3;
var V2 = document.form1.VolumeTick2;
var V1 = document.form1.VolumeTick1;
var V1Qa = document.form1.Volume1a.value
var V1Qb = document.form1.Volume1b.value
var VP1 = document.form1.VolumePrice1.value
var V2Qa = document.form1.Volume2a.value
var V2Qb = document.form1.Volume2b.value
var VP2 = document.form1.VolumePrice2.value
var V3Qa = document.form1.Volume3a.value
var V3Qb = document.form1.Volume3b.value
var VP3 = document.form1.VolumePrice3.value
var V4Qa = document.form1.Volume4a.value
var V4Qb = document.form1.Volume4b.value
var VP4 = document.form1.VolumePrice4.value
var V5Qa = document.form1.Volume5a.value
var VP5 = document.form1.VolumePrice5.value

</script>
</head>

<body>

<p><form name=”form1″ method=”post” onSubmit=”return validateform()” action=”addproduct.asp”>
<input type=”radio” value=”V1″ name=”SetorVolumePrice” checked>Set Price: $
<input type=”text” name=”SetPrice” size=”5″><p>
<input type=”radio” value=”V2″ name=”SetorVolumePrice”>Volume Price<br>
&nbsp;&nbsp;&nbsp;&nbsp; <input type=”checkbox” name=”VolumeTick1″ value=”ON”>Volume
1:&nbsp;&nbsp; Quantity
<input type=”text” name=”Volume1a” size=”1″> to
<input type=”text” name=”Volume1b” size=”1″> =&nbsp;&nbsp; Unit Price: $<input type=”text” name=”VolumePrice1″ size=”4″><br>
&nbsp;&nbsp;&nbsp;&nbsp; <input type=”checkbox” name=”VolumeTick2″ value=”ON”>Volume
2:&nbsp;&nbsp; Quantity
<input type=”text” name=”Volume2a” size=”1″> to
<input type=”text” name=”Volume2b” size=”1″> =&nbsp;&nbsp; Unit Price: $<input type=”text” name=”VolumePrice2″ size=”4″><br>
&nbsp;&nbsp;&nbsp;&nbsp; <input type=”checkbox” name=”VolumeTick3″ value=”ON”>Volume
3:&nbsp;&nbsp; Quantity
<input type=”text” name=”Volume3a” size=”1″> to
<input type=”text” name=”Volume3b” size=”1″> =&nbsp;&nbsp; Unit Price: $<input type=”text” name=”VolumePrice3″ size=”4″><br>
&nbsp;&nbsp;&nbsp;&nbsp; <input type=”checkbox” name=”VolumeTick4″ value=”ON”>Volume
4:&nbsp;&nbsp; Quantity
<input type=”text” name=”Volume4a” size=”1″> to
<input type=”text” name=”Volume4b” size=”1″> =&nbsp;&nbsp; Unit Price: $<input type=”text” name=”VolumePrice4″ size=”4″><br>
&nbsp;&nbsp;&nbsp;&nbsp; <input type=”checkbox” name=”VolumeTick5″ value=”ON”>Volume
5:&nbsp;&nbsp; Quantity
<input type=”text” name=”Volume5a” size=”1″>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp; Unit Price: $<input type=”text” name=”VolumePrice5″ size=”4″><input type=”submit” value=”Submit” name=”B1″ style=”float: right”></p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
&nbsp;</form>
</body>

</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsJan 01.2006 — Can you give us some sample information that people might enter into this?
Copy linkTweet thisAlerts:
@anniebelle82authorJan 01.2006 — Hi there,

Sorry, i shouldve explained the purpose of the form.

This is just one section of the whole form that allows administrators to add products to their ecommerce website.

This section is to allow administrators to choose between using a set price or a volume price for the product (that is going to be added).

The set price is pretty straight forward. The volume price is a bit complicated. Essentially, the volume price is to allow multiple quantities to be purchased at different prices (for example, bulk purchasing will equate to a lesser price per unit).

If Volume 1: was selected

Quantity '1' to '10' = Unit Price: $5

If Volume 2: was selected

Quantity '11' to '20' = Unit Price: $4

If Volume 3: was selected

Quantity '21' to '30' = Unit Price: $3

If Volume 4: was selected

Quantity '31' to '40' = Unit Price: $2

If Volume 5: was selected

Quantity 40+ = Unit Price: $1


As noted in my problem (first post), not all 5 volumes have to be used, but the 5th volume must be used. Eg. the client may use volume 1, 2 and 5. Or alternatively, he may use volume 1 and volume 5..... and so forth.
×

Success!

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