How to add the drop-down list using javascript

"Mahabub Basha" <[email protected]>
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
Hi

I have a dictionary
opts['lists'] = [ 'foo', 'bar', 'baz']

I pass the opts in sample.kid
=========================================
Sample.Kid page
==========================================
<html py:extends="'layout.kid'" xmlns:py="http://purl.org/kid/ns#"
      xmlns:form="mypage">
<head>
<script type="text/javascript">
text_count = 2000;

function Add() {

    var d  = document.getElementById('mylist');

    var id = 'textboxes-' + text_count;

    var newtxt = document.createElement('div');
    newtxt.setAttribute ('id', id);

    newtxt.innerHTML = '<input type="text" name= "' + id + '" />&nbsp;' +
                      '<a href="#" onclick="javascript:RemoveIP(
this.parentNode )">' +
                      '<img src="trash.gif" class="icon" /></a>';
    d.appendChild(newtxt);
}

</script>

</head>
<body>

<h1>Sample Page</h1>
<form action="Sample" method="POST">
<table id="table2" cellpadding="1" cellspacing="0">
<tr>
    <td>
        <div py:for="i in range(0, len(args['textboxes']))">
            <input type="text" name="textboxes-${i}"
value="${args['textboxes'][i]}" />
            <a href="#" onclick='javascript:Remove(this.parentNode)'>
                <img src=" trash.gif" class="icon" /></a>
        </div>
        <div id="mylist"></div>
        <form:error name="gwips" />
    </td>
</tr>
<tr>
    <td></td>
    <td>
        <a href="#" onclick="Add()">Add</a>
    </td>
</tr>
</table>
<input type="submit" name="save" value="Save" />
</form>
=================================================================
In this above page , we add a textboxes using javascript. this above code
working fine.

I need to add one more drop-down list next to textbox. I add the following
line to Add() function.

============================================================

I pass the opts in sample.kid
=========================================
Sample.Kid page
==========================================
<html py:extends="'layout.kid'" xmlns:py="http://purl.org/kid/ns#"
      xmlns:form="netpro">
<head>
<script type="text/javascript">
text_count = 2000;

function Add() {

    var d  = document.getElementById('iplist');

    var id = 'textboxes-' + text_count;

    var newtxt = document.createElement('div');
    newtxt.setAttribute('id', id);

    newtxt.innerHTML = '<input type="text" name= "' + id + '" />&nbsp;' +
                                   '<select name="lists">' +
                                  '<option py:for="myval in opts['lists']"
value="${myval}">${myval}</option>' +
                      '</select>' +
                      '<a href="#" onclick="javascript:RemoveIP(
this.parentNode)">' +
                      '<img src="trash.gif " class="icon" /></a>';
    d.appendChild(newtxt);
}
=============================================================
But i got the error message like this
============================================================
ERROR Message Output:
=============================================================

File "/usr/local/lib/python2.4/site-packages/formencode/htmlfill.py",
line 69, in render
    p.feed(form)
  File "/usr/local/lib/python2.4/site-packages/formencode/htmlfill.py",
line 184, in feed

    HTMLParser.HTMLParser.feed(self, data)
  File "/usr/local/lib/python2.4/HTMLParser.py", line 108, in feed
    self.goahead(0)
  File "/usr/local/lib/python2.4/HTMLParser.py", line 148, in goahead

    k = self.parse_starttag(i)
  File "/usr/local/lib/python2.4/HTMLParser.py", line 268, in parse_starttag
    self.handle_starttag(tag, attrs)
  File "/usr/local/lib/python2.4/site-packages/formencode/htmlfill.py",
line 227, in handle_starttag

    self.handle_option(attrs)
  File "/usr/local/lib/python2.4/site-packages/formencode/htmlfill.py",
line 397, in handle_option
    assert self.in_select, "<option> outside of <select>: %s" %
self.getpos()

TypeError: not all arguments converted during string formatting

============================================================
if i use like this

'<select name="lists">' +
 '<option value="foo">foo</option> ' +
'</select>' +

it will works. But i need to load the drop-down values using opts dictionary

How can i add the drop-down list using javascript?

Please anyone help me

- Mahabub Basha.S

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
FormEncode-discuss mailing list
FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.