2016-08-19 18 views
0

我想將在/ index頁面(屬性地址)和(email)上輸入的文本數據傳遞到/註冊頁面。如何初始化HTML頁面中的元素

問題:

查詢字符串(S)正在進入的網址,但我怎麼填充相應字段/註冊頁面上,在URL中提供的文本數據?

www.juwai.kiwi

<script> 
(function(f, e, t){ 
    initForm(f, e, t); 
}(document.forms[0],'full_name',document.getElementsByName('full_name').valueOf())); 
</script> 
<script> 
function initForm(oForm, element_name, init_txt) { 
    frmElement = oForm.elements[element_name]; 
    frmElement.value = init_txt; 
}; 
var queryStrng = [ 
    { 
     full_name: "dave", 
     email: "[email protected]", 
     property_address: "prop address to do" 
    } 
]; 
//queryStrng[0].full_name = document.getElementsByName("full_name").valueOf(); 
//var oFormObject = document.forms[0]; 

</script> 
+0

你的問題需要更具體的,如果你要得到一個有用的答案。 –

+0

對不起,正在編輯過程中。現在做了羅布。 –

回答

0

試試這個功能:

function GetURLParameter(sParam) 
{ 
    var sPageURL = window.location.search.substring(1); 
    var sURLVariables = sPageURL.split('&'); 
    for (var i = 0; i < sURLVariables.length; i++) 
    { 
     var sParameterName = sURLVariables[i].split('='); 
     if (sParameterName[0] == sParam) 
     { 
      return sParameterName[1]; 
     } 
    } 
}​ 


And this is how you can use this function assuming the URL is, 
http://www.juwai.kiwi/sign-up.html?property_address=abcd&email=myemail%40gmail.com 

var property_address = GetURLParameter('property_address'); 
var email = GetURLParameter('email');` 
+0

調試器說空引用。我不認爲它可以在網頁上找到唯一的表單? –

+0

哎呀,腳本是之前的形式。轉移到下面的表格,工作得很好。 –