473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to validate combos that are dependent?

Hi all,...I have an special situation, that I can not solve.... I need
some help

This is my scenario:

1.- I have n-combos (showing available rooms from an hotel) in my
web-page. The number of combos is not fixed.

2.- Some of the combos are dependent. I mean:

imagine the following situation:
I have 5 combos, combos 1,2,3 have values (free rooms) from 0 to 3, and

combos 4, 5 have values from 0 to 2

combo1 (room type 1)
combo2 (room type 1)
combo3 (room type 1)
combo4 (room type 2)
combo5 (room type 2)

The problem is that combos 1,2 and 3 are DEPENDENT, so the sum of the 3
combos CAN NOT be greater that the total number of free rooms(of that
type)

Again,
combo1.value + combo2.value + combo3.value <= 3

and also combos 4 and 5 are DEPENDENT, so combo4.value + combo5.value
<= 2
How can I writte a js function to validate this values?..

any help would be apreciated..

Thanks all

Alberto

Aug 21 '06 #1
2 1533

Gordowey wrote:
Hi all,...I have an special situation, that I can not solve.... I need
some help

This is my scenario:

1.- I have n-combos (showing available rooms from an hotel) in my
web-page. The number of combos is not fixed.

2.- Some of the combos are dependent. I mean:

imagine the following situation:
I have 5 combos, combos 1,2,3 have values (free rooms) from 0 to 3, and

combos 4, 5 have values from 0 to 2

combo1 (room type 1)
combo2 (room type 1)
combo3 (room type 1)
combo4 (room type 2)
combo5 (room type 2)

The problem is that combos 1,2 and 3 are DEPENDENT, so the sum of the 3
combos CAN NOT be greater that the total number of free rooms(of that
type)

Again,
combo1.value + combo2.value + combo3.value <= 3

and also combos 4 and 5 are DEPENDENT, so combo4.value + combo5.value
<= 2
How can I writte a js function to validate this values?..
Here is something to get you going...

<form action="" id="formA">
<div id="xx">
<span id="errorMsg0"></span><br>
</div>
<div>
<!-- When resetting the form, need to call checkSelects() after
the form has been reset -->
<input type="reset"
onclick="this.form.reset();checkSelects(this.form) ;">
</div>
</form>

<script type="text/javascript">
// Just to add elements, this bit should be HTML but script is a bit
// more concise for posting
var div = document.getElementById('xx');
var oSel = document.createElement('select');

for (var i=0; i<4; i++){
oSel.options[i] = new Option(i, i);
}
var nSel, nSpan;
for (i=0; i<5; i++){
nSel = oSel.cloneNode(true);
nSel.id = "sel_" + i;
nSel.onchange = checkSelects;
if (2 < i) nSel.length = 3;
if (3 == i) {
div.appendChild(document.createElement('br'));
nSpan = document.createElement('span');
nSpan.id = 'errorMsg1';
div.appendChild(nSpan);
div.appendChild(document.createElement('br'));
}
div.appendChild(nSel);
}

// This fn checks the selects, writes message if sum is wrong
// Everything is hard-coded, you may want to change that.

function checkSelects(form){
if (!form.nodeName) {
form = this.form;
}
var msgText0 = '';
var msgText1 = '';
if ( +form.sel_0.value + +form.sel_1.value + +form.sel_2.value 3){
msgText0 = "Ooops, these three must total 3 or less";
}
if ( (+form.sel_3.value + +form.sel_4.value) 2){
msgText1 = "Ooops, these two must total 2 or less";
}
document.getElementById('errorMsg0').innerHTML = msgText0;
document.getElementById('errorMsg1').innerHTML = msgText1;
}

</script>
--
Rob

Aug 21 '06 #2

RobG wrote:
Gordowey wrote:
Hi all,...I have an special situation, that I can not solve.... I need
some help

This is my scenario:

1.- I have n-combos (showing available rooms from an hotel) in my
web-page. The number of combos is not fixed.

2.- Some of the combos are dependent. I mean:

imagine the following situation:
I have 5 combos, combos 1,2,3 have values (free rooms) from 0 to 3, and

combos 4, 5 have values from 0 to 2

combo1 (room type 1)
combo2 (room type 1)
combo3 (room type 1)
combo4 (room type 2)
combo5 (room type 2)

The problem is that combos 1,2 and 3 are DEPENDENT, so the sum of the 3
combos CAN NOT be greater that the total number of free rooms(of that
type)

Again,
combo1.value + combo2.value + combo3.value <= 3

and also combos 4 and 5 are DEPENDENT, so combo4.value + combo5.value
<= 2
How can I writte a js function to validate this values?..

Here is something to get you going...

<form action="" id="formA">
<div id="xx">
<span id="errorMsg0"></span><br>
</div>
<div>
<!-- When resetting the form, need to call checkSelects() after
the form has been reset -->
<input type="reset"
onclick="this.form.reset();checkSelects(this.form) ;">
</div>
</form>

<script type="text/javascript">
// Just to add elements, this bit should be HTML but script is a bit
// more concise for posting
var div = document.getElementById('xx');
var oSel = document.createElement('select');

for (var i=0; i<4; i++){
oSel.options[i] = new Option(i, i);
}
var nSel, nSpan;
for (i=0; i<5; i++){
nSel = oSel.cloneNode(true);
nSel.id = "sel_" + i;
nSel.onchange = checkSelects;
if (2 < i) nSel.length = 3;
if (3 == i) {
div.appendChild(document.createElement('br'));
nSpan = document.createElement('span');
nSpan.id = 'errorMsg1';
div.appendChild(nSpan);
div.appendChild(document.createElement('br'));
}
div.appendChild(nSel);
}

// This fn checks the selects, writes message if sum is wrong
// Everything is hard-coded, you may want to change that.

function checkSelects(form){
if (!form.nodeName) {
form = this.form;
}
var msgText0 = '';
var msgText1 = '';
if ( +form.sel_0.value + +form.sel_1.value + +form.sel_2.value 3){
msgText0 = "Ooops, these three must total 3 or less";
}
if ( (+form.sel_3.value + +form.sel_4.value) 2){
msgText1 = "Ooops, these two must total 2 or less";
}
document.getElementById('errorMsg0').innerHTML = msgText0;
document.getElementById('errorMsg1').innerHTML = msgText1;
}

</script>
--
Rob

thank you very much Rob, that helps me a lot....

good job!

regards, Alberto

Aug 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Keith | last post by:
A2003, Xp Pro. I've designed a form which contains 6 of combos. Three on the left are set up to select fields from a query, three on the right are set up to select values from the corresponding...
0
by: Eric Eggermann | last post by:
Hello, I'm rather a fan of creating classes derived from a combo box with one specific functionality like listing installed printers and whatnot. I call the code to load the combos from the...
3
by: BrianDH | last post by:
Hi I have a form with multi-tabs, and on each tab I have a one combo that has the same values. I populate all 3 combo with the same one datacall/dataset My problem is: when I make a value...
1
by: G .Net | last post by:
Hi I have a DataGrid which has combos in the first field. These combos are populated via a DataView from another table. When I click the header of the field i.e. to sort it, the rows are sorted...
4
by: Jack | last post by:
There used to be a classes and member functions combos on top of the code window (like vb6) Now they are all .cpp listed with the code window underneath it. Where can I find back the old combo...
11
by: Zebra Code | last post by:
hi all i should copy the items of a combo to n other combos. it's not a cycle: With cboColor1 .Items.Add("ffffff") .Items.Add("cecece") ... .SelectedIndex = 0
3
by: sberry | last post by:
I have three arrays... for instance $a = array('big', 'small', 'medium'); $b = array('old', 'new'); $c = array('blue', 'green'); I want to take those and end up with all of the combinations...
3
by: ilikebirds | last post by:
I am looking for a way to have one combo lookup drop down to autopopulate with multiple items based off another combo lookup. I've tried Me!rc1 = DLookup("", "", "Reject_Reason_1='" &...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.