I’m trying to set the hidden field for ‘item_number’ from the Url QueryString for a paypal form.
So the URL will look like this “http://website.com/customize.aspx?item_number=FFFF”
and code:
<script language="javascript" type="text/javascript">
document.getElementById('item_number').Value = Request.QueryString('item_number');
</script>
<input type="hidden" name="item_number" value="">
But this doesnt work for me. Whats wrong here???? is there a better way?
getElementByIdonly finds elements by their ID. Your hidden doesn’t have theidofitem_number; it has that name, however. If you addid="item_number"to yourinput, then the code should work. You also need to move your script to after the DOM element. Otherwise, it will run before theinputexists in the document.Update
Just noticed another mistake. You’re setting a
Valueproperty, andRequest.QueryString('item_number')is also invalid. It looks like you’re confusing ASP.NET code with JavaScript. The correct property name for the hidden input isvalue(lowercase). There is no equivalent ofRequest.QueryStringin JavaScript. Rather, to extract query string values, see this answer for a good way to do so.