2014-01-23 69 views
0

我有一個html頁面,它有兩種形式,並在提交它的調用perl腳本。但在腳本中,cgi param沒有得到任何值。未傳遞給Perl的jQuery元素cgi

HTML代碼 -

<fieldset class="col_4" name="BetweenRange"> <legend>Range Comparison</legend> 
<form action="call_range.pl" method="post" id="range1" target="Range1"> 
<table width="100%" border="1"> 
    <tr> 
    <td><input name="r1_1stdate" type="text" id="from1" required/><input name="r1_2nddate" type="text" id="to1" required/></td> 
</form> 
<form action="call_range.pl" method="post" id="range2" target="Range2">  
    <td><input name="r2_1stdate" type="text" id="from2" required/><input name="r2_2nddate" type="text" id="to2" required/></td> 
    </tr></form> 
    <tr> 
    <td><iframe id="I3" align="left" name="Range1" >Your browser does not support inline frames or is currently configured not to display inline frames. 
</iframe></td> 
    <td><iframe id="I4" align="left" name="Range2" >Your browser does not support inline frames or is currently configured not to display inline frames. 
</iframe></td> 
    </tr> 
</table> 
</fieldset> 

腳本放在這裏 -

$(function() { 
    $("#from1").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     changeYear: true, 
     numberOfMonths: 1, 
     onClose: function(selectedDate) { 
    $("#to1").datepicker("option", "minDate", selectedDate); 
     } 
    }); 
    $("#to1").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     changeYear: true, 
     numberOfMonths: 1, 
     onClose: function(selectedDate) { 
    $("#from1").datepicker("option", "maxDate", selectedDate); 
     } 
    }); 
    <!-- RangeComparison form submit , getting called after selecting 2nd date--> 
    $("#to1").change(function() { this.form.submit(); }); }); 



    $(function() { 
    $("#from2").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     changeYear: true, 
     numberOfMonths: 1, 
     onClose: function(selectedDate) { 
    $("#to2").datepicker("option", "minDate", selectedDate); 
     } 
    }); 
    $("#to2").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     changeYear: true, 
     numberOfMonths: 1, 
     onClose: function(selectedDate) { 
    $("#from2").datepicker("option", "maxDate", selectedDate); 
     } 
    }); 
    <!-- RangeComparison form submit , getting called after selecting 2nd date--> 
    $("#to2").change(function() { 
    this.form.submit(); }); 
    }); 

Perl代碼 - 使用嚴格的; 使用CGI;

my $query = CGI->new; 
print $query->header; 

my $from1 = $query->param('from1'); 
my $to1 = $query->param('to1'); 

print "</br>Value passed for form1 $from1</br>$to1"; 
print $query->end_html; 

這是哪裏出錯了?如果有人能幫忙,我將不勝感激。

鏈接的jsfiddle http://jsfiddle.net/jDd5U/

回答

2
  1. 您HTML是認真無效。你有表格不允許的表格。瀏覽器錯誤恢復很可能會在它嘗試生成有效的DOM時破壞它們。使用a validator
  2. 表單控件的name被用作提交數據中的關鍵字。您正在嘗試查找未提交的id
+0

1.我已將它放在表格中以使其正確對齊。我運行了一個驗證,並且知道需要進行很多更改。你在說這個嗎? '$(「#to1」)。change(function(){this.form.submit();}); }); ' 我對UI設計完全陌生。 –

+0

1. [不要使用表格進行佈局](http://designshack.net/articles/10-css-form-examples/)。 2.編號' param('from1')' – Quentin

+0

感謝您的糾正。我已經改變了pe​​rl代碼來獲取元素名稱並且工作。 –