Copy link to clipboard
Copied
I'm making a form with a dropdown list that exports a variety of values based on user selection. Some of those values need to be web links; however, I would prefer they were not visible as the whole link, but rather as links embedded within text. Is that possible, and if so, how would I do it?
(Be aware, my knowledge of Javascript is pretty basic, but I'm good at copy/paste and I can change field names!)
Hi,
If you wish add an item with an url in your dropdown menu
you have to add it with an export value starting with link... (link2, link3...)
then you have to modify the init script in document-level
and define the link... object with the text, the url and the text size.
Try with the link3 object...
FYI, as it is not possible to use the auto size in a rich text field, you will have to set the size manually indicating it in the link object.
...Copy link to clipboard
Copied
To the document-level script!
But have a look on the file of my previous answer, the script of the function has been updated.
Else:
function gradeLevelStandardScoreOrLink(ind) {
try {
this.removeField("theText"+ind);
this.removeField("theLink"+ind);
} catch(e) {}
this.getField("Standard_score"+ind).display=display.visible;
this.getField("Standard_score"+ind).setAction("MouseUp", "app.beep(0);");
if (event.changeEx!="0") {
var f=this.getField(event.target.name);
for (var i=0; i<f.numItems; i++) {
if (event.changeEx==f.getItemAt(i,true)) {
if (event.changeEx.indexOf("link")==0) {
var coord=this.getField("Standard_score"+ind).rect;
this.getField("Standard_score"+ind).display=display.hidden;
var f=this.addField("theText"+ind, "text", 0, coord);
f.richText=true;
f.readonly=true;
spans=[{
text: eval("allLinks."+event.changeEx+".theText"),
textColor: color.blue,
textSize: eval("allLinks."+event.changeEx+".theSize"),
underline: true,
}];
f.richValue=spans;
var f=this.addField("theLink"+ind, "button", 0, coord);
f.setAction("MouseUp","app.launchURL(\""+eval("allLinks."+event.changeEx+".theURL")+"\",true);");
f.setAction("MouseEnter","spans=[{text: \""+eval("allLinks."+event.changeEx+".theText")+"\",textColor: color.red,textSize: "+eval("allLinks."+event.changeEx+".theSize")+",underline: true,}];this.getField(\"theText"+ind+"\").richValue=spans;");
f.setAction("MouseExit","spans=[{text: \""+eval("allLinks."+event.changeEx+".theText")+"\",textColor: color.blue,textSize: "+eval("allLinks."+event.changeEx+".theSize")+",underline: true,}];this.getField(\"theText"+ind+"\").richValue=spans;");
} else this.getField("Standard_score"+ind).buttonSetCaption(f.getItemAt(i,true));
break;
}
}
} else {
this.getField("Standard_score"+ind).buttonSetCaption("");
this.getField("theText"+ind).value="";
}
}
@+
Copy link to clipboard
Copied
Huh. Still didn't work. I'm attaching the updated form. I added a form reset button, and you can see that where I've made selections from the assessment dropdown, if it was a link, the reset button will remove the text, but when you mouse-enter, that reappears. If I select an assessement from the dropdown that only exports text, that will not clear at all. Thank you again!
Copy link to clipboard
Copied
That's because you hard-coded the text into the code. Instead of doing that you should read the field's current contents, and then change their color, if it's not blank.
Copy link to clipboard
Copied
Hi,
Here is your file where I modifyed a bit the script and I place a script in your Clear button.
for (var i=1; i<=9; i++) {
this.removeField("theText"+i);
this.removeField("theLink"+i);
this.getField("Standard_score"+i).display=display.hidden;
}
this.resetForm();
Concerning the function script, I removed the "try" statment for removing the fields.
In the previous script, I placed "removeField" with "try" statment in the case these fields don't exist but that doesn't work... That only works without the "try" statment and there is no error message if the field doesn't exist... I don't know why!
@+
Copy link to clipboard
Copied
Because removeField doesn't throw an Exception if the field name you supply to it doesn't exist. It doesn't return any values, either.
Copy link to clipboard
Copied
That's what I noticed, thanks!
@+