2013-08-27 3 views
0

에 제출하지 않습니다. 내 html 코드의 제출 버튼이 onclick 이벤트에 응답하지 않습니다. . 제 html 코드를 살펴보고 내가 잘못 된 위치를 알려주십시오. 위치를 사용하고 있습니다 .href 보통, 그러나, 그것도 doesnt는 여기에서 일한다. 라디오 버튼 옵션 "yes"또는 "no"에 따라 2 개의 URL 사이를 전환하는 기능을 사용했습니다.HTML 제출 버튼은 해당 URL의

미리 감사드립니다. 이 유형의 입력 제출해야하고 당신이 그것을 클릭하면

<html> 
<head> 
<style type="text/css"> 
body{ 
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; 
font-size:12px; 
} 
p, h1, form, button{border:0; margin:0; padding:0;} 
.spacer{clear:both; height:1px;} 
/* ----------- My Form ----------- */ 
.myform{ 
margin:0 auto; 
width:400px; 
padding:10px; 
} 


/* ----------- stylized ----------- */ 
#stylized{ 
border:solid 2px #000000; 
background:#ebf4fb; 
width:500px; 
height:350px; 
} 
#stylized h1 { 
font-size:14px; 
font-weight:bold; 
margin-bottom:8px; 
} 

#stylized label{ 
display:block; 
font-weight:bold; 
text-align:left; 
width:140px; 
float:left; 
} 

#stylized form{ 
float:left; 
font-size:12px; 
<!--padding:4px 2px;--> 
<!-- border:solid 1px #aacfe4;--> 
width:100px; 
margin:2px 0 20px 10px; 
} 
#stylized table, th, td 
{ 
font-size:12px; 
width:400px; 
border: 1px solid black; 
} 
th 
{ 
width:10%; 
background-color: black; 
color: white; 
} 
#stylized button.custom-submit { 
float: left; 
clear: none; 
margin-left: 50px; 
} 

    </style> 
    <script> 
    $(function(){ 

    $('myform').submit(function(event){ 
    event.preventDefault(); 
    window.location = $('input[type=radio]:checked').val(); 
    }); 
    }); 
    </script> 

    </head> 


<body> 
<div id="stylized" class="myform"> 
<form id="form" name="form"> 


<label>New Data set : 
    </label> 
    <input type="radio" name="url" value="Inputs1.html" /> Yes 
    <input type="radio" name="url" value="ResultsPage.html" /> No 

    <br> 
    <label>Dataset description: 
    </label> 
    <input type ="text" name= "Dataset" size="30"><br><br><br> 
    <table id="Previous Datasets"> 
    <tr> 
    <th>Check</th> 
    <th>Token Number</th> 
<th>Dataset description</th> 
</tr> 
<tr> 
    <td><input type="checkbox"> </td> 
    <td>234567</td> 
<td>MHEX North America Dataset</td> 
</tr> 
<tr> 
    <td><input type="checkbox"> </td> 
    <td></td> 
<td></td> 
</tr> 
<tr> 
<td><input type="checkbox"> <td> 
<td></td> 

</tr> 
<tr> 
<td><input type="checkbox"> </td> 
<td></td> 
<td></td> 
</tr> 
<tr> 
    <td><input type="checkbox"> </td> 
    <td></td> 
<td></td> 
</tr> 
</table> 
<div style="text-align: center"><br> 
<input type="Submit" name="submit" value="Submit" class="submit" onClick="gotoResults()"> 
<div class="spacer"></div> 
</form> 
</div> 
</body> 
+0

여기에만 관련 정보를 표시하도록 게시물을 수정하십시오 : 당신의 제출 HTML 및 귀하의 JS에서 – Bigood

+2

U 버튼 클릭에서 메서드를 호출했지만 정의가 없습니다. – Sasidharan

+0

$ ('입력 : 드롭 다운 메뉴') 란 무엇입니까? – VahidNaderi

답변

1

는, 폼 태그는 어디 가서 결정하기 위해 보았다된다.

이렇게 할 경우 작업 명령을 양식에 추가하고 해당 작업 명령에서 새 페이지를 지정해야합니다. 제출 공격, 쿼리 문자열 형태의 요소와 새로운 페이지로 가져올 때 서버에 GET 요청을 보내드립니다

<form id="form" name="form" action="newpage.html" method="get"> 

이런 식으로 뭔가 ....

반면에 자바 스크립트 함수를 호출하고 양식의 필드 값을 직접 가져 오려면 양식 태그에서 버튼을 가져온 다음 제출 버튼이 아닌 일반 버튼으로 설정하십시오), 그리고 지금처럼 onclick에서 javascript 함수를 호출하십시오.

1

대신 온 클릭의 폼에 onsubmit 사용할 필요가 :

<form id="form" name="form" onsubmit="gotoResults(); return false;"> 

반환 거짓이 양식을 제출 중의 기본 동작을 방지하고 (조치를하지 않은 경우) 같은 페이지로 이동합니다.

0

그 작업 ...

자바 스크립트

$(document).ready(function() { 
      $("#sub").click(function() { 
       var x = $("#select").val(); 
       if (x == "yes") { 
        window.location.href = "http://www.google.com"; 
       } 
       else { 
        window.location.href = "http://www.yahoo.com"; 
       } 
      }) 
     }); 

CSS

body{ 
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; 
font-size:12px; 
} 
p, h1, form, button{border:0; margin:0; padding:0;} 
.spacer{clear:both; height:1px;} 
/* ----------- My Form ----------- */ 
.myform{ 
margin:0 auto; 
width:400px; 
padding:10px; 
} 


/* ----------- stylized ----------- */ 
#stylized{ 
border:solid 2px #000000; 
background:#ebf4fb; 
width:500px; 
height:350px; 
} 
#stylized h1 { 
font-size:14px; 
font-weight:bold; 
margin-bottom:8px; 
} 

#stylized label{ 
display:block; 
font-weight:bold; 
text-align:left; 
width:140px; 
float:left; 
} 

#stylized form{ 
float:left; 
font-size:12px; 
<!--padding:4px 2px;--> 
<!-- border:solid 1px #aacfe4;--> 
width:100px; 
margin:2px 0 20px 10px; 
} 
#stylized table, th, td 
{ 
font-size:12px; 
width:400px; 
border: 1px solid black; 
} 
th 
{ 
width:10%; 
background-color: black; 
color: white; 
} 
#stylized button.custom-submit { 
float: left; 
clear: none; 
margin-left: 50px; 
} 

HTML

<div> 
     <div id="stylized" class="myform"> 
      <form id="form" name="form" method="post"> 
      <label> 
       New Data set : 
      </label> 
      <select id="select"> 
       <option value="Yes">Yes</option> 
       <option value="No">No</option> 
      </select> 
      <br> 
      <br> 
      <label> 
       Dataset description: 
      </label> 
      <input type="text" name="Dataset" size="30"><br> 
      <br> 
      <br> 
      <table id="Previous Datasets"> 
       <tr> 
        <th> 
         Check 
        </th> 
        <th> 
         Token Number 
        </th> 
        <th> 
         Dataset description 
        </th> 
       </tr> 
       <tr> 
        <td> 
         <input type="checkbox"> 
        </td> 
        <td> 
         234567 
        </td> 
        <td> 
         MHEX North America Dataset 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <input type="checkbox"> 
        </td> 
        <td> 
        </td> 
        <td> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <input type="checkbox"> 
        <td> 
        <td> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <input type="checkbox"> 
        </td> 
        <td> 
        </td> 
        <td> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <input type="checkbox"> 
        </td> 
        <td> 
        </td> 
        <td> 
        </td> 
       </tr> 
      </table> 
      <div style="text-align: center"> 
       <br> 
       <input id="sub" type="Submit" name="submit" value="Submit" class="submit"> 
       <div class="spacer"> 
       </div> 
      </div> 
      </form> 
     </div> 
    </div> 
+0

이 코드를 복사하여 붙여 넣기 만하면됩니다 .it 윌 일 .. – Sasidharan

관련 문제