15 Maj 2008

Dodawanie opcji do Selecta

Dodawanie opcji do selecta  z bieżącego okna i z nowego okna

<HTML>

  <HEAD>
    <SCRIPT LANGUAGE="JavaScript">

      var tmpval = "";
      function add_option() {

        nr = document.forms[0].miasto.length
        ntyp = new Option('Lublin', nr)
        document.forms[0].miasto.options[nr] = ntyp
      }
      function add_option2() {
        tmpval = document.forms[0].tmpval.value

        if (tmpval != "") {
          nr = document.forms[0].miasto.length
          ntyp = new Option(tmpval, nr)
          document.forms[0].miasto.options[nr] = ntyp
          document.forms[0].tmpval.value = ""
        }
      }
      function new_option() {
        config = 'toolbar=no, location=no, directories=no, status=no, menubar=no, width=250, height=30, scrollbars=no, resizable=no, top=150, left=480'
        win = window.open("", "option", config)

        body = '<title>Dodaj miasto</title>'
        body += '<script>function add_option(){'
        body += 'opener.document.forms[0].tmpval.value = document.forms[0].noption.value'
        body += 'opener.document.forms[0].dodaj.focus()'
        body += 'self.close()'
        body += '}<\/script><form><INPUT TYPE="text" NAME="noption" value=""><INPUT TYPE="button" name="dodaj" value="Dodaj"' + 'onClick="' + "add_option()" + '"></form>'

        win.document.write(body)
      }

    </SCRIPT>
  </HEAD>

  <BODY>
    <br><br><br>
    <FORM METHOD=POST ACTION="select.html" name="adres">
      <TABLE>
        <TR>
           <TD><select name="miasto">
                 <option value="1">Warszawa</option>
                </select>
             </TD>
           <TD><INPUT TYPE="button" name="dodaj" value="nowe okienko dodaj" onClick="new_option()"
              onFocus="add_option2()"></TD>
           <TD><INPUT TYPE="button" name="dodaj2" value="dodaj" onClick="add_option()"></TD>
           <TD><INPUT TYPE="hidden" name="tmpval" value=""></TD>
        </TR>
      </TABLE>
    </FORM>
  </BODY>

</HTML>