0

我需要一点帮助。首先,我在表单中有一些来自数据库的值的页面,如下所示:

out.println("<form method=\"post\" action=\"update.jsp?id=" + 
                    rs.getString(1) +"\" onSubmit=\"return editF(this)\" id=\"editDiv"+ rs.getString(1) +"\" >" + SelectCat() +" </form>")
public String SelectCat()
    {
        String result = "<select name=\"category\" >";
        try
        {
            String request = "SELECT * FROM cat";
            Statement st = getConnection().createStatement();
            ResultSet rs = st.executeQuery(request);
            while (rs.next())
            {
                result += "<option value=\"" + rs.getString(1) + "\">" + rs.getString(2) + "</option>";
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        result += "</select>";
        return result;
    }

我的javascript函数是

 function editF(form)
{
    alert("a");
    string header = form.header.value;
    string text = form.text.value;
    string category = form.category.selectedIndex.value;
    var e = document.getElementByName("category");
    //var category = e.selectedIndex;
    form.action = form.action + "&header="+header+"&text="+text+"&categoryID="+category;
    return true;
};

但我无法获得选定的价值。你能帮助我吗?谢谢!

4

1 回答 1

1
var category = form.category.options[ form.category.selectedIndex ].value;

另外,javascript 不是强类型语言,在声明它的时候不能定义它的类型。相反,使用var.

于 2012-05-05T15:42:59.580 回答