What do you do when your prompts are more dynamic? For instance, what if you always want the default to be the second value in a value prompt drop down, and those values change each month? Here's a simple JavaScript (JS) solution to accomplish this.
You will need to add 3 html items to your prompt page for each prompt for which you would like to have the dynamic default applied. In this post, we're only going to do one.
Step 1 - Add an html item to the left of the prompt. Place the following in there:
<span id="promptname">
You can replace that with whatever name you would like to associate with this prompt. This name needs to be unique for each prompt to which you apply this method.
Step 2 - Add an html item to the right of the prompt. Place the following in there:
</span>
Step 3 - Add an html item to the right of the html item in step 2. Place the following in there:
<script type="text/javascript">
var theSpan = document.getElementById("promptname");
var theSelect = theSpan.getElementsByTagName("select");
theSelect[0].options[3].selected=true;
</script>
Notice that the name used in step 1 is used again here in step 3. This will not work correctly if they don't match. Also, the number in brackets next to the options (step 3, line 4) determines what item in the drop-down list will be selected. In this example, I used 3 to select the 2nd option in the list. You can change that number to select the appropriate option in the list as needed.
The end product should look like this -
The end product should look like this -
There you have it: default prompt value in 3 easy steps. Enjoy!
But it keeps refreshing the page. Any solution to stop that after 1st execution?
ReplyDelete