2012-04-26 68 views
0

我必须根据选择1的结果,其产生<input>场+选择2.生成输入获取值,并将其添加到网址参数

像这两个选择字段:

jQuery(function($) 
{ 
     $('select[name="nb_adultes"], select[name="nb_enfants"]').change(function() 
     { 
       var total_a = parseInt($('select[name="nb_adultes"]').val()); 
       var total_e = parseInt($('select[name="nb_enfants"]').val()); 

       if (total_a + total_e > 10) 
       { 
         alert("La somme du nombre d'adultes et d'enfants ne doit pas dépasser 10"); 
       } 
       else 
       { 
         $("#input_appended").empty(); 

         for(var j=0; j < total_a; j++) 
         $("#input_appended").append('<label for="date_naissance">Date de naissance Adulte</label><input type="text" name="date_naissance_a_'+j+'"/><br />'); 

         for(var k=0; k < total_e; k++) 
         $("#input_appended").append('<label for="date_naissance">Date de naissance Enfant</label><input type="text" name="date_naissance_e_'+j+'"/><br />'); 
       } 
     }); 
}); 

我需要检索生成的每个输入字段的值,并保存它们整合成一个URL PARAM:

实施例:

选择场1个显示NUM BER“2”,选择场2显示数字“1”,所以我有3个输入框,我需要这样的:

var select_1-1 = input VAL1 
var select_1-2 = input VAL2 
var select_2-1 = input VAL3 

var url = "http://www.url.com/page.php?select_1-1=VAL1&select_1-2=VAL2&select_2-1=VAL3" 

任何帮助将是非常非常赞赏,谢谢!

回答

0

没有HTML,所以你必须自己找出选择器。

var VAL1 = $(select_1-1).val(); 
var VAL2 = $(select_1-2).val(); 
var VAL3 = $(select_2-1).val(); 

var url = "http://www.url.com/page.php?select_1-1="+VAL1+"&select_1-2="+VAL2+"&select_2-1="+VAL3; 
+0

感谢的答案,但是这不是我想要的,我想要检索所产生的VAL输入然后把他们在我的网址 – user990463 2012-04-27 07:29:05

0

要检索的输入值,并将其存储在变量做:

var VAL1 = $(select_1-1).val(); 
var VAL2 = $(select_1-2).val(); 
var VAL3 = $(select_2-1).val(); 

然后你可以把它们放在一起在一个名为myurl像另一个变量:

var myurl = "http://www.url.com/page.php?select_1-1="+ 
VAL1+ 
"&select_1-2="+ 
VAL2+"&select_2-1="+ 
VAL3; 

然后,如果你想在myurl使用的新窗口中打开:

window.open(myurl, '_blank') 


相反,如果你想只是myurl添加到您的网址,而不是刷新页面使用:

var myurl = "/page.php?select_1-1="+ 
    VAL1+ 
    "&select_1-2="+ 
    VAL2+"&select_2-1="+ 
    VAL3; 
window.history.pushState('', "Title", myurl); 
相关问题