Hello, I\'m having some trouble with getting my \"textArea\" inputs to be displa
ID: 3592162 • Letter: H
Question
Hello, I'm having some trouble with getting my "textArea" inputs to be displayed in the "textField" area of the window. I was able to create each radio button, panel, and checkboxes, but am also struggling with getting the text effects to actually happen. Help would be greatly appreciated :)
Below is the work description and an example of what the program is wanted look like, it doesn't need to be exactly like it, just needs the essential functions.
Assignment Description: During this homework, you will be designing and implementing a simple text processor application. As shown in the screenshot below, the left hand side TextArea (while is scrollable), allows the user to either type of copy and paste the text to be processed. Your text processor allows the user the change the font size of the text based on the Radio button selections. As the user is selecting the appropriate font size button, the textArea will change font size of the text. Large is selected by default Analysis can be done in three ways, word count, vowel count, and character count. The analysis type is given as check boxes. The user can select one, two, or all three analysis types. As, the user select this option, the analysis results textField shows the analysis results. Note: You can use a suitable layout such as BorderLayout, GridLayout, and combinations of them in your implementation. JTextArea Resources: https://docs.oracle.com/iavase/tutorial/uiswing/components/textarea.html JTextField Resources: https:l/docs.oracle.com/javase/tutorial/uiswing/components/textfield.html Submission Instructions: Submit a zip file containing your solution to this homework that includes all java files of the project.Explanation / Answer
hen might you use this?
It’s pretty easy to set a field’s default value through the list settings in the browser UI, so why might you need Javascript to set a default field value? The reason is that field default values can only take static values or simple formulae based on the current user or today’s date. If that meets your needs, then I’d definitely recommend sticking with that method. Sometimes, though, you may want the form to fill with default values based on the user’s interaction with the previous page, and that’s exactly where this method comes in.
How does it work?
In short, we add some Javascript to the page that runs when the body is loaded. This Javascript parses the page’s query string, locates the HTML objects that are rendered by the relevant SharePoint fields, and sets their value based on the information in the query string.
getTagFromIdentifierAndTitle
The most important part of our solution is the “getTagFromIdentifier” function. This function finds the HTML element rendered by a given SharePoint FormField control. It takes the following parameters:
Here’s a partial table of SharePoint column types and their corresponding “identifiers” and “tagNames”:
*Lookups are a bit more complicated because Lookup FormFields render differently when the target list contains more than 20 items. See the end of the post for an example.
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}
fillDefaultValues
Now that we have the HTML elements that we want to set, we need the values with which to set them. In our solution, we wrote the “fillDefaultValues” function, which parses the page’s querystring and then uses the values to set the field defaults.
function fillDefaultValues() {
var qs = location.search.substring(1, location.search.length);
var args = qs.split("&");
var vals = new Object();
for (var i=0; i < args.length; i++) {
var nameVal = args[i].split("=");
var temp = unescape(nameVal[1]).split('+');
nameVal[1] = temp.join(' ');
vals[nameVal[0]] = nameVal[1];
}
// Set HTML element default values here
}
_spBodyOnLoadFunctionNames
In most cases SharePoint pages are based on a master page that contains the “body” element. These content pages can’t directly add a function to the body’s onload event. In order to work around this limitation, SharePoint provides the “_spBodyOnLoadFunctionNames” array. When the body is loaded, the onload event handler executes each function whose name is contained in this array. We added “fillDefaultValues” to the array so that it would run when the body’s onload event fires.
_spBodyOnLoadFunctionNames.push("fillDefaultValues");
All Together Now
With the script above, you can set most different field types to any value from the querystring – or any other source that javascript can access. Below is a full example of the script we use to set the default value of a Lookup field based on an ID stored in the querystring. You’ll notice that setting a Lookup field is a bit more complicated than some other field types. The reason is that Lookup FormFields are rendered with different HTML when the target list contains more than 20 items.
Enjoy!
<script type="text/javascript">
// This javascript sets the default value of a lookup field identified
// by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
// identified by <<QUERYSTRING VARIABLE NAME>>
// Customize this javascript by replacing <<FIELD DISPLAY NAME>> and
// <<QUERYSTRING VARIABLE NAME>> with appropriate values.
// Then just paste it into NewForm.aspx inside PlaceHolderMain
_spBodyOnLoadFunctionNames.push("fillDefaultValues");
function fillDefaultValues() {
var qs = location.search.substring(1, location.search.length);
var args = qs.split("&");
var vals = new Object();
for (var i=0; i < args.length; i++) {
var nameVal = args[i].split("=");
var temp = unescape(nameVal[1]).split('+');
nameVal[1] = temp.join(' ');
vals[nameVal[0]] = nameVal[1];
}
setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals["<<QUERYSTRING VARIABLE NAME>>"]);
}
function setLookupFromFieldName(fieldName, value) {
if (value == undefined) return;
var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
// if theSelect is null, it means that the target list has more than
// 20 items, and the Lookup is being rendered with an input element
if (theSelect == null) {
var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
ShowDropdown(theInput.id); //this function is provided by SharePoint
var opt=document.getElementById(theInput.opt);
setSelectedOption(opt, value);
OptLoseFocus(opt); //this function is provided by SharePoint
} else {
setSelectedOption(theSelect, value);
SharePoint Field Type identifier tagName Single Line of Text TextField input Multiple Lines of Text TextField input Number TextField input Currency TextField input Choice (dropdown) DropDownChoice select Lookup (single)* Lookup select Lookup (multiple) SelectCandidate; SelectResult select Yes/No BooleanField inputRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.