I am trying to programmatically embed the "selected" attribute in a select list using xquery but am running into problems. Basically I am writing a form that calls itself and trying to set the select value to that of the previous value. What is shown in the following code does not show the logic for obtaining the request field, but it does show the problem with trying to set the selected attribute programmatically.
Here is the code that fails (which you can run in CQ to verify this): xquery version "1.0-ml"; let $selected := if (true()) then "selected=""selected""" else "" return <html xmlns="http://www.w3.org/1999/xhtml"> <body> <h3>RefXPress Phase 1 Book Titles</h3> <form name="test" action="analysis-and-statistics.xqy" method="post"> Book Title Sort Order: <select name="order"> <option value="one" {$selected}>Select one</option> <option value="two">Select two</option> </select> </form> </body> </html> Apparently it doesn't like adding an attribute unless the attribute is hard-coded and the value is optional. So changing the selected attribute to a hard-coded value as follows will generate the HTML page without error. Note that in XHTML, the "selected" attribute must also have a value, but it is merely the presence of the attribute and not the value that causes the select list option to be selected when displaying the form. xquery version "1.0-ml"; let $sel:= """selected""" return <html xmlns="http://www.w3.org/1999/xhtml"> <body> <h3>RefXPress Phase 1 Book Titles</h3> <form name="test" action="analysis-and-statistics.xqy" method="post"> Book Title Sort Order: <select name="order"> <option value="one" selected={$sel}>Select one</option> <option value="two">Select two</option> </select> </form> </body> </html> The only problem with that is that the selected attribute is hard-coded, therefore the item will always be selected. The same problem exists trying to programmatically add the "checked" attribute to a list of radio buttons. I would like to be able to programmatically set the attribute without having to use javascript to iterate through the select list to set the appropriate selected index. Perhaps there are some other ways to solve this. Any help would be much appreciated! If this cannot be done with xquery, does anyone have an example of doing this in javascript within an xquery page? Thank you! Tim Meagher _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
