2013-08-27 5 views
0

최종 사용자가 다양한 옵션을 선택하여 하드웨어 장치 목록을 만들 수있는 양식이 있습니다. 선택 상자 (기본값)에서 값을 선택하지 않으면 DIV에서 특정 필드 (IP 할당)를 숨기고 싶지만 일단 선택 상자에서 값을 선택하면 추가 필드가 포함 된 DIV를 표시하려고합니다. JS에서 PHP 함수를 호출하여 숨겨진 필드의 내용을 다시 채울 수 있습니까?선택 상자가 변경 될 때 DIV 표시/숨기기

   <fieldset style="width:30%; float:left;"> 
        <label>IP Allocation</label> 
        <select name="ipv4b" style="width:92%;"> 
         <?php 
          $ipv4_values = array("id", "ip"); 
          display_options_list($ipv4_values, "ipv4", "id", true); 
         ?> 
        </select> 
       </fieldset> 

enter image description here

+0

를보다 효율적으로 사용 아약스 호출, 페이지 새로 고침 – SarathSprakash

답변

0

당신은 그것을 보여주는 다음 기본적으로 그것을 숨기고 더 나을 것입니다.

이 그 일의 가장 기본적인 방법은 다음과 같습니다

// I'm just assuming here, I don't know the class, name or etc of 
// your select list 
$('select[name="datacenter"]').change(function() 
{ 
    // Check if it's empty 
    if($(this).val() != '') 
    { 
     // Again, I'm assuming here since I don't know the name of your class 
     $('.ip-allocation-div').show(); 
    } 

    else 
    { 
     // No value set, hide it. 
     $('.ip-allocation-div').show(); 
    } 
}); 

는보다 구체적인 예를 들어 클래스 이름을 제공하십시오.

JavaScript를 통해 PHP 함수를 호출하는 경우 AJAX 호출을해야합니다.
여기 기본적인 예입니다

$.ajax(
{ 
    url: 'path/to/page.php', 

    // This should be an object of data you want to send, 
    // remove if no data will be sent 
    data: {}, 
    type: 'POST', 

    // Your callback function 
    success: function(response) 
    { 
     // Do something with the data 
    } 
}) 
+0

완벽한없이 그것을, 감사합니다! –

관련 문제