2017-09-13 44 views
0

我有我的.cshtml頁面鏈接到一個SSRS報告:追加輸入字段值的URL上.cshtml頁

<div class="col-md-8"> 
 
    <a href="http://xxx.xx.xx.x/ReportServer/Pages/ReportViewer.aspx?%2fCompany_Reporting%2fpayr0001&rs:Command=Render&StartDate=01/09/2017" target="_blank" >Timesheet Status Report</a> 
 
</div>

我需要從傳遞值我日期控制作爲相對於上述硬編碼日期的參數:

<div class="form-group"> 
 
    <input type="date" class="form-control" id="datefrom"> 
 
</div>

我曾嘗試追加一個onclick=myfunction()到URL添加日期值,但無法讓它工作。

function getStartDate() { 
    return document.getElementById("datefrom").value; 
} 

任何幫助將不勝感激。

乾杯。

+1

你可以顯示你試圖添加的onclick函數嗎? – PredatorIWD

+0

這是什麼'myfunction()'做的?只是發佈HTML不會讓我們知道實際發生的情況 – Se0ng11

+0

Kathleen

回答

1

在日期更改屬性中創建錨標記的href。在旅途中構建href。

$('#datefrom').change(function(){ 
    $('#IdOfAnchorTag').attr('href','http://xxx.xx.xx.x/ReportServer/Pages/ReportViewer.aspx?%2fCompany_Reporting%2fpayr0001&rs:Command=Render&StartDate=' + $('#datefrom').val()); 
}); 

檢查相應的字符串..

+0

'IdOfAnchorTag'表示錨標籤的id。好的......但在OP代碼中沒有'id'。編輯你的答案;)我的意思是......解釋。 (大聲笑)你知道OP想要做什麼,我想。 –

+0

哈哈..常見..它會有一個Id,類名.. ..東西..考慮到他給的數據,我想它會在那裏。 – Sameer

0

這是你想要做什麼,據我可以告訴(重複的問題?):
append to url and refresh page

爲了獲取日期在正確的格式中,您必須在功能正文中執行以下操作:
new Date($('input[type=date]').val()).toLocaleFormat();

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleFormat

另外,您可能要爲日期輸入使用'onblur'/ blur事件,或者將事件處理函數連接到專門用於該目的的新按鈕。這是因爲點擊日期輸入(可能打開某種日曆小部件,取決於瀏覽器和瀏覽器版本),onclick/click事件就會觸發。

0

在將日期值傳遞給網址之前,請嘗試將日期轉換爲dd-MM-yyyyMM-dd-yyyy而不是dd/MM/YYYY。 因爲我認爲當url會誤解「/」,所以你應該用「 - 」替換。 然後如有必要,您可以轉換回舊的格式。