Difference between revisions of "Ns formvalueput"

From AOLserver Wiki
Jump to navigation Jump to search
(Added examples. Noted a bunch of bugs. Will annotate ns_tagelement too.)
(OK, I think it's correct now :-))
Line 27: Line 27:
  
 
'''EXAMPLES'''
 
'''EXAMPLES'''
Check box "a" from the set a, b:
+
 
 +
:Check box "a" from the set a, b:
 
<pre><nowiki>
 
<pre><nowiki>
% set checks {<form>
+
  % set checks {<form>
<input type="checkbox" name="ex" value="a">a</input>
+
  <input type="checkbox" name="ex" value="a">a</input>
<input type="checkbox" name="ex" value="b">b</input>
+
  <input type="checkbox" name="ex" value="b">b</input>
</form>
+
  </form>
}
+
  }
<form>
+
  <form>
<input type="checkbox" name="ex" value="a">a</input>
+
  <input type="checkbox" name="ex" value="a">a</input>
<input type="checkbox" name="ex" value="b">b</input>
+
  <input type="checkbox" name="ex" value="b">b</input>
</form>
+
  </form>
  
% ns_formvalueput $checks ex a
+
  % ns_formvalueput $checks ex a
<form>
+
  <form>
<input type="checkbox" name="ex" value="a" CHECKED>a</input>
+
  <input type="checkbox" name="ex" value="a" CHECKED>a</input>
<input type="checkbox" name="ex" value="b">b</input>
+
  <input type="checkbox" name="ex" value="b">b</input>
</form>]
+
  </form>
 
</nowiki></pre>
 
</nowiki></pre>
Set the value of hidden form field "foo" to "bar"
+
 
 +
: Set the value of hidden form field "foo" to "bar"
 +
 
 
<pre><nowiki>
 
<pre><nowiki>
% set hidden {<input type="hidden" name="foo">}
+
  % set hidden {<input type="hidden" name="foo">}
<input type="hidden" name="foo"/>
+
  <input type="hidden" name="foo"/>
  
% ns_formvalueput $hidden foo bar
+
  % ns_formvalueput $hidden foo bar
<input type="hidden" name="foo" value="bar">
+
  <input type="hidden" name="foo" value="bar">
 
</nowiki></pre>
 
</nowiki></pre>
Set the value of textarea "textarea" to "new value":
+
 
 +
: Set the value of textarea "textarea" to "new value":
 +
 
 
<pre><nowiki>
 
<pre><nowiki>
% set ta {<form>
+
  % set ta {<form>
<textarea name=textarea>Old value</textarea>
+
  <textarea name=textarea>Old value</textarea>
</form>}
+
  </form>}
<form>
+
  <form>
<textarea name=textarea>Old value</textarea>
+
  <textarea name=textarea>Old value</textarea>
</form>
+
  </form>
  
% ns_formvalueput $ta textarea {new value}
+
  % ns_formvalueput $ta textarea {new value}
<form>
+
  <form>
<textarea name=textarea>new value</textarea>
+
  <textarea name=textarea>new value</textarea>
</form>
+
  </form>
 
</nowiki></pre>
 
</nowiki></pre>
  
 
'''NOTES'''
 
'''NOTES'''
In AOLServer 4.5.0 (and all previous versions):
+
:In AOLServer 4.5.0 (and all previous versions):
* Checkboxes are treated exactly like radio buttons. That is, all other boxes with the same name are unchecked.  
+
:* Checkboxes are treated exactly like radio buttons. That is, all other boxes with the same name are unchecked.  
* There is no mechanism for explicitly unchecking a checkbox.
+
:* There is no mechanism for explicitly unchecking a checkbox.
* In part because [[ns_tagelement]] does not strip single quotes from attribute values, the type, name, and value attribute values for each element must be either bare or enclosed by double quotes.
+
:* In part because [[ns_tagelement]] does not strip single quotes from attribute values, the type, name, and value attribute values for each element must be either bare or enclosed by double quotes.
* [[Ns_formvalueput]] cannot be used with or to create well-formed XHTML 1.0 documents:
+
:* [[Ns_formvalueput]] cannot be used with well-formed XHTML 1.0 documents, nor will it create them:
** The CHECKED and SELECTED attributes are minimized (i.e., have no value) and are always in upper case.  
+
:** The CHECKED and SELECTED attributes are minimized (i.e., have no value) and are always in upper case.  
** <nowiki><input></nowiki> elements encoded using the XML syntax <nowiki><input </nowiki>'''/>''' will cause syntax errors in the output.
+
:** <nowiki><input></nowiki> elements encoded using the XML syntax <nowiki><input </nowiki>'''/>''' will cause syntax errors in the output (the value attribute is inserted between the trailing '''/''' and the trailing '''>''').
 +
 
  
 
----
 
----
  
 
[[Category Documentation]] - [[Category Core Tcl API]]
 
[[Category Documentation]] - [[Category Core Tcl API]]

Revision as of 21:54, 8 February 2008

Man page: not in source tree


NAME

ns_formvalueput - Sets the value of input elements in HTML documents

SYNOPSIS

ns_formvalueput htmlpiece dataname datavalue

DESCRIPTION

This command sets the value of an HTML input element with NAME=dataname (of any type) to the given datavalue. In the following descriptions, all attribute names are handled in case-insensitive fashion (as required by HTML)
The elements (tags) & types supported are:
  • INPUT
image
ignored
submit
ignored
reset
ignored
checkbox
will be checked if the NAME attribute matches the dataname (case insensitive) and the VALUE attribute matches the datavalue (case-sensitive)
radio
will be checked if the NAME attribute matches the dataname (case insensitive) and the VALUE attribute matches the datavalue (case-sensitive)
  • TEXTAREA
If the NAME attribute matches the dataname, all the enclosed text up to the next </textarea> tag will be replaced by the datavalue.
  • SELECT
If the NAME attribute of the SELECT tag matches the dataname, this will find the first enclosed OPTION tag with a VALUE attribute that matches datavalue, and set its SELECTED attribute. All other enclosed OPTION tags will have their SELECTED attribute removed.

EXAMPLES

Check box "a" from the set a, b:
  % set checks {<form>
  <input type="checkbox" name="ex" value="a">a</input>
  <input type="checkbox" name="ex" value="b">b</input>
  </form>
  }
  <form>
  <input type="checkbox" name="ex" value="a">a</input>
  <input type="checkbox" name="ex" value="b">b</input>
  </form>

  % ns_formvalueput $checks ex a
  <form>
  <input type="checkbox" name="ex" value="a" CHECKED>a</input>
  <input type="checkbox" name="ex" value="b">b</input>
  </form>
Set the value of hidden form field "foo" to "bar"
  % set hidden {<input type="hidden" name="foo">}
  <input type="hidden" name="foo"/>

  % ns_formvalueput $hidden foo bar
  <input type="hidden" name="foo" value="bar">
Set the value of textarea "textarea" to "new value":
  % set ta {<form>
  <textarea name=textarea>Old value</textarea>
  </form>}
  <form>
  <textarea name=textarea>Old value</textarea>
  </form>

  % ns_formvalueput $ta textarea {new value}
  <form>
  <textarea name=textarea>new value</textarea>
  </form>

NOTES

In AOLServer 4.5.0 (and all previous versions):
  • Checkboxes are treated exactly like radio buttons. That is, all other boxes with the same name are unchecked.
  • There is no mechanism for explicitly unchecking a checkbox.
  • In part because ns_tagelement does not strip single quotes from attribute values, the type, name, and value attribute values for each element must be either bare or enclosed by double quotes.
  • Ns_formvalueput cannot be used with well-formed XHTML 1.0 documents, nor will it create them:
    • The CHECKED and SELECTED attributes are minimized (i.e., have no value) and are always in upper case.
    • <input> elements encoded using the XML syntax <input /> will cause syntax errors in the output (the value attribute is inserted between the trailing / and the trailing >).



Category Documentation - Category Core Tcl API