Below is my code to get row id:
<script>
function myFunction(x){
alert("row idex="+x.rowIndex);
var rowID=x.rowIndex;
}
</script>
Now I want to pass this row id to another page through input tag of HTML
<input type="hidden" name="rowid" value="here i need to pass the javascript variable that contain row id vale" >
I'm a beginner here so detailed explanation would be appreciated.
Try this
<script type="text/javascript">
function myFunction(x){
alert("row idex="+x.rowIndex);
var rowID=x.rowIndex;
document.getElementById("rowid").value = rowID
}
</script>
Change input to
<input type="hidden" name="rowid" id="rowid" value="" >
When you navigate through pages, your js script gets refreshed on each page load. So you can not directly pass js variable from one page to another. Instead of that you can set cookie on one page and retrieve that cookie on next page.
document.cookie="username=test; expires=Thu, 18 Dec 2013 12:00:00 UTC";
var x = document.cookie;
<script type="text/javascript">
//This function will set the cookie
function myFunction(x){
alert("row idex="+x.rowIndex);
var rowID=x.rowIndex;
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = "row =" + rowID + "; " + expires;
}
//To retrieve the set cookie value call following function
function get_cookie_value()
{
return username=getCookie("row");
}
</script>
JavaScript doesn't provide that kind of functionality to pass the value of varibale to other page, Though you can do it by storing your value in browser's local storage and get that value back on other page.
No html element needed to pass the variable of js.
//suppose you want to pass 25 as value of variable rowid
var rowid = 25;
//now store rowid variable in your browser
//window.localStorage.setItem('name to get and set value',your variable);
window.localStorage.setItem('rowid',rowid);
//now get that rowid variable in your other page
//window.localStorage.getItem('name to get and set value');
rowid_value = window.localStorage.getItem('rowid');
alert(rowid_value);