2012-05-09 34 views
-2

在我的第一頁上,我有兩個單選按鈕,每個都有一個值。單擊鏈接轉到第2頁時,以下for循環運行並獲取選中按鈕的值。 (該腳本起作用,我已經測試過):將變量傳遞給新函數(在新頁面上)

function func1(){ 
    var info = document.Information; 
    for(var i1 = 0;i1 < info.length;i1++){ 
     if (info.elements[i1].type == "radio" && info.elements[i1].checked) { 
     ordertype = info.elements[i1].value; 
     alert(ordertype);  
     } 
    } 
} 

變量ordertype在函數之外聲明。第二頁我有這個功能上的按鈕,點擊運行:

function func2(){ 
    alert(ordertype); 
} 

訂單類型,現在不確定......我該如何正確的變量傳遞給新的功能?

+1

JavaScript執行上下文不在頁面之間共享。 –

+1

Cookie?會議? localStorage的?請求參數? – j08691

+0

頁面一打開頁面二與'window.open'? – Jeff

回答

0

如果使用JavaScript ...你可以通過查詢字符串傳遞:

function func1() { 

     var info = document.Information; 

     for (var i1 = 0; i1 < info.length; i1++) { 
      if (info.elements[i1].type == "radio" && info.elements[i1].checked) { 
       ordertype = info.elements[i1].value; 
       break; 
      } 
     } 
     location = 'page.html?value=' + ordertype; 
    } 

或者只需要添加一個提交按鈕到表單中。

And method = post to you form-tag and you will get the value of the selected radiobutton in the querystring without the use of the javascript?