Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

httpunit: ScriptException of Select Onchange

Frank Shaw
2008-04-20
2013-04-26
  • Frank Shaw
    Frank Shaw
    2008-04-20

    Hi

    The problem is old,it works without charset ,but it didnt work with charset?
    I try to use HttpUnitOptions.setDefaultCharacterSet("iso-8859-8") to change the charset to "iso-8859-8" ,"UTF-8",but I failed.

    thanks for you help.
    Frank China

    /******************************************
    * working platform: chinese windows ;    *
    * httpunit: ver 1.6.2 ;                  *
    * language: chinese province and city ;  *  
    ******************************************/
    1. Result of the html file without charset : ---------------------- GOOD

         city length : 3

    2. Result of the html file with charset : ------------------------ BAD (SCRIPT NO WORK)

         city length : 1

    ----------------1-- SAMPLE CODE ---------------
         ...

         HTMLPage hp = resp.getReceivedPage();
         WebForm form = hp.getFormWithName("test1");
         form.setParameter("province", "四川");
         System.out.println("city length : "+form.getOptionValues("city").length);
         form.setParameter("city", "四川111");

         ...

    ----------------2-- form.html ---------------

    <form name="test1">
    <select onchange='setcity();out_city();' name='province' >
    <option value=''>--chinese--</option>
    <option value=河北>河北</option>
    <option value=北京>北京</option>
    <option value=四川>四川</option>
    </select>
    <select name='city' id = 'city' ></select>
    <script src="getcity2.js"></script>
    <script>initprovcity('','');</script>
    </form>

    ----------------3-- getcity2.js ---------------

    function setcity(city) {
        switch (document.test1["province"].value) {
            case "河北" :
                var cityOptions = new Array(
                "河北111", "河北111",
                "河北222", "河北222",
                "河北333", "河北333");
                 break;
            case "北京" :
                var cityOptions = new Array(
                "北京111", "北京111",
                "北京222", "北京222",
                "北京333", "北京333");
                break;
            case "四川" :
                var cityOptions = new Array(
                "四川111", "四川111",
                "四川222", "四川222",
                "四川333", "四川333");
                break;
            default:
                var cityOptions = new Array("", "");
                break;
        }
       
        document.test1["city"].options.length = 0;   
        for(var i = 0; i < cityOptions.length/2; i++) {
            document.test1["city"].options[i]=new Option(cityOptions[i*2],cityOptions[i*2+1]);

            if (document.test1["city"].options[i].value==city)
            {
                //alert("here put City ok!");
                document.test1["city"].selectedIndex = i;
            }
        }
    }

    function initprovcity(province,city) {
        var provObject = document.test1["province"];
        for(var i = 0; i < document.test1["province"].options.length; i++) {
            if (document.test1["province"].options[i].value==province)
            {
                //alert("prov put is ok");
                document.test1["province"].selectedIndex = i;
            }
        }
        setcity(city);
    }

     
    • Frank Shaw
      Frank Shaw
      2008-04-20

      ----------------2.5-- formCharSet.html ---------------

      <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

      <form name="test1">
      <select onchange='setcity();out_city();' name='province' >
      <option value=''>--chinese--</option>
      <option value=河北>河北</option>
      <option value=北京>北京</option>
      <option value=四川>四川</option>
      </select>
      <select name='city' id = 'city' ></select>
      <script src="getcity2.js"></script>
      <script>initprovcity('','');</script>
      </form>