Pass hidden field value using Jquery

怎甘沉沦 提交于 2019-12-08 18:30:41

easily accomplished just do the following

var value = $("#randomdirectory").val();
url:'Upload.html?field1='+value ,

thats it ..

Just give a name to the hidden field.

<input name="field1" type="hidden" id="randomdirectory" value="randomvalue"/>
url: 'Upload.html?field1='+$("#randomdirectory").val()

If I got your question right and the ID is randomly generated then you need something of this type:

url: 'Upload.html?field1=newvalue&field2=' + $('[type="hidden"]').val();

Assuming that this is a parameter to an ajax call (as others already have), a slightly better practice is this:

url: 'Upload.html',
data: { field1: $('#randomdirectory').val() }

This will ensure that your query string is URL encoded properly (jQuery handles it for you).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!