disallow certian values based on other fields value!?

hi guys, assume i have 2 fields {field1} and {field2} both set to select with list of options…

i want to do this: if field 1 is selected as option X then field 2 is not allowed to select option S in it

both has no “title” and not required, i tried to make title and set them as required, but i am using another field {field3} that is supposed to re-load all field1 and field2 to default… so i get them blank and can be saved ( all of them have first value in db as blank or N/A) so the reload is working just as required… but i can’t make it set purposly on another option of the other field is selected specific thing

please advise some easy way, i know you probably you dealt with such thing earlier

I think that the standard ajax refresh is not suitable for this. Changing field 1 triggers the refresh of field 2. But this is done upon a sql statement. So somehow you need to be able to exclude the X when S is selected. But with some difficult sql it’s doable I guess. Other option would be to test upon on change event, on blur event of in the onvalidat event to test the values in relation to each other.

well, lets forget about selecting specific option based on other select field… i guessed it is complicated somehow

how about this one? how i can make it work onLoad or when loading the form… instead of ajax?

http://www.scriptcase.net/forum/showthread.php?6434-again-multiple-records-form-discussion-and-selecting-working-row

please have a look

Hi,
regarding your initial question, you have to fill your select fields from tables (automatic) and not manual.
Just a sample to give you an idea.

Create two tables tb_sel1, tb_sel2.

tb_sel1:

s1_code | exclude_sel2
n | c
x | a,f,s //Note: if x is selected option a, f and s won’t be available in {select2}
y |
z | b,k

lookup for {select1}: SELECT s1_code FROM tb_sel1
Section Ajax Processing check the box and mark {select2}

tb_sel2:

s2_code
a
b
c
f
k
s

Lookup for {select2}: SELECT s2_code FROM tb_sel2 WHERE NOT FIND_IN_SET(s2_code,(SELECT exclude_sel2 FROM tb_sel1 WHERE s1_code = {select1}))

That should do it.

jsb

Great solution. Never used find_in_set; being honest wasn’t aware of it’s excistance.

seems perfect like always jsb :slight_smile: he is the man of the job Albert, the guy of no limitation, trust me :slight_smile:
will try this way once i understand it indeed :slight_smile: and let you know if any issues
thanks a lot jsb, highly appreciated ur inputs and help

Mike

[QUOTE=itsme3;24253]seems perfect like always jsb :slight_smile: he is the man of the job Albert, the guy of no limitation, trust me :slight_smile:
will try this way once i understand it indeed :slight_smile: and let you know if any issues
thanks a lot jsb, highly appreciated ur inputs and help

Mike[/QUOTE]

Everybody has his/her limitations Mike. But the community is what makes us all strong. Would be great if you would share the knowledge you build now with other users later. In this speed, you’ll be a pro soon.

Defiantly Albert, i understand your point, we all have limitations… my experience with sc is about 2 months only, mostly i struggle with stuff like if are not built in such as advanced coding, java, or workarounds like the one in this topic… believe me i love to help or answer questions that i know or i can do!!

Okayyyyy, i took closer look at that, and looks fine and logic, but i think is it more complicated that the need? or not related? i am not sure…

let me explain some more please

i have one from (multiple records) getting data from one table with 4 fields {select1} {select2} {select3} {select4}

options of these select lists are foreign keys from other small tables that feed the data… so in the form table are stored as 0,1,2,3,4,5 (set by sc lookup > automatic) and they work fine. same for {select2},{select3},{select4} i have 1,2,3, 4 that is actually in the “primary” table something like this: id 0= “Main”, id 1= “secondary” and id 3= “3rd party” id 4=“vacant”… etc

now the form (multiple records form) when i select option 1 in field: {select1} i want the select 2 select option 2 automatically and if i select option 2 in select1 then change select to option 3 for example… something like force the value of the other select field to have specific option from its field if selected something else??

seems ajax business, but not for my level for sure :slight_smile:

so if make sense and can be done in some way it will be really helpful… instead of relying on making all my default values the ones i want them to have and make the ajax reload them on onChange from another select field… sometimes you want specefic option of the other select, not the first one :slight_smile:

alright, again, sorry for writing long, i am just trying to explain, and sorry for my english

appreciated any hint, idea, solution or workaround

cheers

Mike

Before somebody is racking his brain :-), just to clarify.
You want to exclude one or maybe more options from a select field aaannnd additionally have it pre set to a specific value based on the selection made in the select field before aaannnd cascading through to the successive select fields?

jsb

yes i racked my brain bro jsb since day one tried the sc :slight_smile: and you guys taught me some nice things here in the forums so i am trying to apply and innovate lool

4 select fields… in each row of the mutliple records form… when selecting option A from select1 then select2 changes its value to option B alone (B is in the list of options)

like if you do it by clicking the drop down list arrow and select option B manually…
or like you force select2 to have option B - that is if select1 was selected as option A…

i guess this is easier to explain… that ajax solution will make the field value “0” if it is disable, so i got use of that for testing… so i changed my B options to 0 (as id) so it is going automtically to 0 if was disabled :slight_smile: smart huh!? after all is not practice, so if you want Option C be selected, can’t be done this way :frowning:

just dont be mad please, i know you hate me now, forget it all at all if there is racking issues :slight_smile:

Well, the question is not field1 and field2 rather what should happen with field3 and … since you programmatically changed the value of field2? Should it also be changed? If so field4 may be changed as well.
If this is kind of the functionality you want, believe me, you need a table for this. Resistance is futile! :slight_smile:
It may look overkill at the moment and you can certainly hardcode id, but imagine in a year or so down the road somebody wants more options or more categories or different defaults. That’s a nightmare.

Anyways, the decision is up to you. The basic idea is to determin (onChange) which value has been selected and what’s the default for the next field and pass it as additional parameter (i.d. $default) to your Javascript method.

onChange ({select1})

$default2 = 0;
switch({select1})
{
case ‘A’:
$default2 = ‘X’;
$color = ‘grey’;
$disable = true;
break;

case ‘B’
$default2 = ‘Y’;
$color = ‘blue’;
$disable = false;
break;
}

sc_ajax_javascript(‘your_js_method’,array({row_cnt},$default2,$color,$disable);

JS method: (add the necessary parameters)

field = ‘your_field_name_’+row_nr;
document.F1[field].value = default;
document.F1[field].disabled = disable;
document.F1[field].style.backgroundColor = color;

Keep in mind, since you change the value programmatically, there is no onChange event triggered for {select2} you can use to change the other fields.

jsb

I wounder if you came from Mars dear, this is really perfect, and you covered also the explanation and the the advice is awesome, you are right, i will change the process without resistance, I wanted it handy and you proofed it will work work :slight_smile:

thanks is not enough for your efforts dear, really appreciated :o

Mike