Passing hidden field from one page to another in querystring
Don't waste your time learning jQuery . It's not very difficult and it makes javascript writing much easier. There are also many jQuery plugins like jquery.url .
Also, as other posters have suggested, you might not want to put the value of the hidden field in the query string if you care about getting it displayed to the user. However, if data is present in a hidden field, it will always be possible to find it if they want to look.
If you really want to put the hidden field in the query string and then retrieve it via jQuery without jQuery:
hiddenFieldPage.aspx
Will this form lead the user to process Page.aspx? datum = someValue when it is sent. Perhaps you can also just use a regular link if nothing needs to be sent at the same time.
<form method="GET" action="processingPage.aspx">
<input type="hidden" name="datum" value="someValue">
<input type="submit">
</form>
or by inserting the value from the code:
RegisterHiddenField("datum", "someValue");
processingPage.aspx
This script will display an alert box with the value "datum" from the url - if the form method is set to "GET":
<script type="text/javascript">
function getUrlParam( key ) {
// Get the query and split it into its constituent params
var query = window.location.search.substring(1);
var params = query.split('&');
// Loop through the params till we find the one we want
for( var i in params ) {
var keyValue = params[i].split('=');
if( key == keyValue[0] ) {
return keyValue[1];
}
}
// Didn't find it, so return null
return null;
}
alert( getUrlParam("datum") );
</script>
If the form method was set to "POST" (as it usually was in ASP.NET), then the "data string" will not be in the query string and you will have to re-place it on the page:
RegisterHiddenField( "datum", Request.Form["datum"] );
To get the hidden value on the second page:
var datum = document.Form1.item("datum").value;
alert( datum );
source to share
You can easily submit a form on one page that points to another page using the parameter action
. For example, inside page1.aspx, enter the following:
<form action="page2.aspx" method="GET">
<input type="hidden" name="username" value="joenobody" />
<input type="submit" />
</form>
Since you are using "GET" as a method instead of "POST", you can use Javascript to parse the URL and get the passed value. Alternatively, you can use ASPX to store the value of the username field somewhere else on the page. I don't know ASPX (or ASP, or something Microsoft really), but if you can find a way to output something like the following (and use jQuery ), it might do what you need. To be honest, it looks like you are wrong about something. Can you modify your question to be more specific about what the general object you are trying to accomplish?
<div id="some_div"><%= Request.form("username") %></div>
<script type='text/javascript'>
var value_needed = $('#some_div').html();
</script>
source to share
Assuming you mean the hidden meaning of an HTML form, your field will be submitted along with all other fields when the form is submitted. If you submit via GET, your "hidden" field will appear as text in the URL. If you do not want the data in a hidden field to be visible to users, do not put a meaningful value in this field.
source to share
If you're using aspx you don't need to parse the query string with JavaScript or even use <form method="GET" ...>
. You can submit the form to a second page aspx
, retrieve the value in C # or VB, and then write it to a JavaScript client variable. Something like that:
page1.aspx
<form method="POST" action="page2.aspx">
<input type="hidden" name="myHiddenServerField" value="myHiddenServerValue">
<input type="submit">
</form>
page2.aspx
<script type="text/javascript">
var myHiddenClientValue = '<%= Request.Form['myHiddenServerField']; %>';
</script>
The above client side JavaScript version called myHiddenClientValue
will be set to value 'myHiddenServerValue'
after POST.
This might be a bad idea, because if it myHiddenServerField
contains single quotes or a newline character, then the installation on the client in page2.aspx
may fail. Injecting ASP.NET Server Variables in Client JavaScript and Injecting ASP.NET Server Variables in JavaScript JavaScript Part 2 addresses exactly these issues and addresses them by using a server-side class that ensures that the values ββwritten to the client are executed correctly.
source to share