Hi All,
I am trying to populate a text field based on what the user chooses in a drop down that contains the 50 United States of America.
So...let's say for now that I want the text field to say "Birmingham" if the user chooses "Alabama".
The only thing I have so far is totally wrong:
function setText()
{
var statechoice = State.value;
switch (statechoice) {
case 1:
Text1.rawValue = "Filing is required in Alabama";
break
case 2:
Text1.rawValue = "Very cold and Filing is required in Alaska";
break
default:
Text1.rawValue = "Choose a state please";
break
}
Solved! Go to Solution.
Views
Replies
Total Likes
You can try some thing like below..
Otherwise, Switch statement evaluates only to the value that is passed next to the switch command..
var statechoice = State.rawValue;
switch (statechoice) {
case "AL":
Text1.rawValue = "Filing is required in Alabama";
Text1.rawValue = Text1.rawValue + setText();
break;
case "AK":
Text1.rawValue = "Very cold and Filing is required in Alaska";
break;
default:
Text1.rawValue = "Choose a state please";
break;
}
//Added a function inside the same event and calling this function in the above switch case statements.
function setText(){
switch (otherDropDown.rawValue) {
case "Yes":
return "Yes Selected";
break;
default:
return "No Selected";
break;
}
}
Hope this helps..
Thanks
Srini
Views
Replies
Total Likes
Few things to mention.
1) You can get the selected value from the dropdown by using rawValue property.. But in your code you have used "State.value"..It should be "State.rawValue"..
2) In the Case statement:
case 1/2/3 etc.. are values of the selected value from the State dropdown. If you assign "AL" for Alabama, then you need to use "case "AL":"
function setText()
{
var statechoice = State.rawValue;
switch (statechoice) {
case "AL":
Text1.rawValue = "Filing is required in Alabama";
break;
case "AK":
Text1.rawValue = "Very cold and Filing is required in Alaska";
break;
default:
Text1.rawValue = "Choose a state please";
break;
}
Find my changes to your script above..
Thanks
Srini
HI Srini,
Yes...correct..excellent...thanks. This works.
And, is there any way for the case condition to evaluate more than one thing?
What if I wanted to select the code to execute based on the fact that the user selected Alaska AND he selected YES or NO in another drop down?
Would that be:
case ("AK" & othervariable=="YES"):
Or does each case only evaluate a single condition?
Thanks,
Joe
Views
Replies
Total Likes
You can try some thing like below..
Otherwise, Switch statement evaluates only to the value that is passed next to the switch command..
var statechoice = State.rawValue;
switch (statechoice) {
case "AL":
Text1.rawValue = "Filing is required in Alabama";
Text1.rawValue = Text1.rawValue + setText();
break;
case "AK":
Text1.rawValue = "Very cold and Filing is required in Alaska";
break;
default:
Text1.rawValue = "Choose a state please";
break;
}
//Added a function inside the same event and calling this function in the above switch case statements.
function setText(){
switch (otherDropDown.rawValue) {
case "Yes":
return "Yes Selected";
break;
default:
return "No Selected";
break;
}
}
Hope this helps..
Thanks
Srini
Views
Replies
Total Likes
Views
Likes
Replies