Tip

How To Retrieve The Value Of A "Notes" Radio Button In A Javascript Code

If Javascript is useful to integrate in a Domino application, difficulties comes very quickly when you want to use values calculated, or entered by a user, in a field and Javascript. This problem is clear : on one hand, javascript is "written" when the page is generated by Domino and sent to the browser and on the other hand, fields are filled only when the user will do that. So, how modify the code of a javascript depending of a field value if it's yet written ? The solution is to use the field name twice in the same form. Once it will be used to name a "Notes" field, and twice to name an HTML Form written in the same page. In the example below, the problem was to use a radio button to select a picture to show, and to store the choice for a future usage. This problem comes very often, for instance when a user wants to choose a tool in a catalog, or if he wants to configurate his own web portal. The example lets the user choosing a picture between 5 and then select it.
In the form, place three fields, hidden from web browsers :

$$HTMLHead will be "computed for display" and will content this code as value :
"<script LANGUAGE=\"JavaScript\">
<!--"+@Newline+
" function rollOver(Tag,Src){
document.images[Tag].src = Src; return;
}

var pict1 = new Image();
var pict2 = new Image();
var pict3 = new Image();
var pict4 = new Image();
var pict5 = new Image();
pict1.src=\'/icons/picts/pict1.gif\';
pict2.src=\'/icons/picts/pict2.gif\';
pict3.src=\'/icons/picts/pict3.gif\';
pict4.src=\'/icons/picts/pict4.gif\';
pict5.src=\'/icons/picts/pict5.gif\';"+@NewLine+
"// -->
</script>"

TheList is the field where we will define the list of choices for the radio
button.
It will be computed for display too and will content, in our case, this code as
value :
"first|pict1":"second|pict2":"third|pict3":"fourth|pict4":"fifth|pict5"
If the value of the list depends on other things in the application, it's
possible to use a dblookup at this place.

Radio1 is a radio button field which is generated by a formula.
The formula will contain "TheList" as value.

Then write this code as "passthru HTML" :
<INPUT TYPE="radio" NAME="radio1" VALUE="" onClick="rollOver('picture',.src) ">
<SCRIPT>
for(var i=0; i<document.forms[0].elements.length;i++) {
var thisRadio = document.forms[0].elements[i];
if(thisRadio.value == "")
thisRadio.checked = true;
}
</SCRIPT>
<p>
<img src="/icons/picts/empty.gif" BORDER="0" NAME="picture" />
</p>

this last HTML code will allow the browser to update the choice of the radio
button.

The first Computed Text will contain this code :
_name := @Left(TheList;"|");
_alias := @Right(TheList;"|");
@Implode("<INPUT TYPE=\"radio\" NAME=\"radio1\" VALUE=\""+_alias+"\"
onClick=\"rollOver(\'picture\',"+_alias+".src) \">"+_name;"<BR>")
It will create the same form, but with the dynamic content.

The second Computed Text will only contain the name of the "Notes" radio button
: radio1
It will allow us to give to the javascript the right selected value.

And to finish, you can add an Action Button Submit with this classical code :
@Command([FileSave]); @Command([FileCloseWindow])
It will allow us to save the document and, then to retrieve the selected value
in the Notes field "radio1".

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.