html get방식의 자동폼 생성

2014. 3. 17. 17:3699. 정리전 - IT/11. Java

http://syaku.tistory.com/12

 

 

Javascript Source : test.js

 


// 최초 호출
function xmlCall(form) {
    var oExe = new ObjectHandler();
    oExe.form = form;
    oExe.objForm();
    oExe.params();
    alert(oExe.xmlSend);
}

function ObjectHandler() {
    this.form;
    this.objForm = ObjectForm;
    this.xmlSend = "";
    this.params = CreateParams;
}

// 해당 폼 알아내기
function ObjectForm() {
    var intCnt = document.forms.length;
    for (var i = 0; i < intCnt; i++) {
        if (document.forms[i].id == this.form) {
            return this.objForm = document.forms[i];
        }
    }
}

// 해당 폼의 엘리먼트 모두를 get 방식으로 조절
function CreateParams() {
    var intCnt = this.objForm.length;
    var regExp = /[&]/;

    for (var y = 0; y < intCnt; y++) {
        if (this.objForm[y].name != "") {
            this.xmlSend += "&" + this.objForm[y].name + "=" + escape(this.objForm[y].value);
        }
    }
    this.xmlSend = this.xmlSend.replace(regExp, "");
}

 

 

 

Example Source

 

< html>< head>< title> xml send파라미터자동생성 < /title>
<script language='JavaScript' type='text/JavaScript ' src=' test.js '></script>
</head>
<body>
<form id=' one ' onsubmit=xmlCall(this.id);>
 <input type="text" name="eletxt_a" value=' one엘리먼트 '>
 <input type="text" name="eletxt_b" value=' a '>
 <input type="submit" value='확인 '>
</form>
<form id=' two ' onsubmit=xmlCall(this.id);>
 <input type="text" name="eletxt_a" value=' two엘리먼트 '>
 <input type="text" name="eletxt_b" value=' '>
 <input type="submit" value='확인 '>
</form>
</body>
</html>