I'm looking to set a variable based on some security for the user logged into and then use that value within JQuery.
This is the setting the variable:
<c:set var="hasResDetailAccess" value="false"/>
What JQuery would be used to retrive that vlaue
jQuery(document).ready(
function() {
var display = $(#frank).text();
});
Actually what you are trying with <c:set> and jQuery both are different thing. <c:set> is useful while translating jsp to servlet i.e. on server side
and 'jQuery' is used to process value on the client side i.e. in the browser.
So if you want a variable within jQuery just add it to any scope i.e request,session,context or application as per your requirement and retrieve it in jsp.
For example in Servlet,
add
request.setAttribute("hasResDetailAccess",hasResDetailAccess);
And in JSP just put code as below,
jQuery(document).ready(
function() {
var hasResDetailAccess= ${hasResDetailAccess} ;
});
${hasResDetailAccess} will fetch value of the variable regardless of the scope and set it to the jQuery variable `hasResDetailAccess. And latter on you can retrieve that jQuery Variable in HTML page anywhere any point of time you need.
Try printing the value in a hidden input an retrieve it from there:
<input type="hidden" value="<c:out value="${hasResDetailAccess}"/>" id="hasResDetailAccess">
and retrieve it with
var display = $('#hasResDetailAccess').val();
Related
i am hoping someone will help me, i am pulling out my hair for the last few hours...!
I am using asp.net web forms with c#
I have the following button in my menu , this button opens up a page that lists selected properties for realtor…
htmlCode.Append("<button type='button' class='btn btn-basic' id='btnEnquire' onclick='openEnquiryPage()'> <span class='glyphicon glyphicon-th-list'></span> View my list </button>");
function openEnquiryPage() {
location.href = "EnquiryPage.aspx";
//get the list from the storage into the hidden field
//getListOfProperties();//not in use...
}
The list is stored in localstorage as Json, I can see the correct data in the text box on the page
var retrievedData = localStorage.getItem("propertyArray");
proplist2.value = retrievedData;
declared as follows in asp.net control
<asp:TextBox ID="TextBox1" runat="server" Text="initial"></asp:TextBox>
BUT in the hidden field, the data is always = ""
<asp:HiddenField ID="txtPropList" runat="server"></asp:HiddenField>
javascript to populate the hidden field...
function getListOfProperties() {
document.getElementById("body_content_txtPropList").value = retrievedData;
var proplist2 = document.getElementById("body_content_txtPropertyList");
proplist2.value = retrievedData;
}
when I debug the following lines in the code behind ...
Page.ClientScript.RegisterStartupScript(this.GetType(),"prop", "getListOfProperties();",true);
_propertyListJson = txtPropList.Value;
propertyListJson I always = “”
Thank-you in advance.!
If you want to use the hidden field then you should use
<%=txtPropList.ClientID%>
as on when you render the page and see it in inspect element server would render the different Id so it would not store the value in hidden field simply so it is feasible to use ClientID to create the static mode. But as on when you call the javascript function from the c# code then it would call the javascript function but it would not wait for it and execute the next line of code as on at that time the value is not store in hidden field so it would return the null value.
If you want then call the function of javascript on page load event and then click the button and retrieve the value it would successfully retrieve the value but i dont think that these would be the feasible code from my opinion
I suggest to create the WebAPI which would simply get the the data from the localstorage and perform the operation
And webAPI can be easily called from javascript using ajax call
I hope this would be helpful and answer is satisfactory 😊☺
Thank You ☺🙂
im using codeigniter in that one view file having form. one place textarea field come form js file like this
test1.js
var html = "<textarea class='gradx_code' id='gradx_code' name='button_gradient' style='display:block;'></textarea>";
im storing this textarea value in database by using name='button_gradient'
now i want to get this value from database and place at textarea value for updating this field for next time so im assign a database value to a js variable like this in view file
test1.php(view)
var textarea = '<?php echo $settings[0]->text_value ?>';
this textarea variable im useing in js file like this by using gradx_code in textarea id
test1.js
gradx.gx('#gradx_code').html(textarea);
but it is not work properly how i can do it help me
use it directly as php:
gradx.gx('#gradx_code').html('<?php echo $settings[0]->text_value ?>');
EDIT: Or you can load this value inside a cookie with php:
setcookie('text_value', $settings[0]->text_value, 0, '/');
,and call it wherever you need it with javascript:
gradx.gx('#gradx_code').html($.cookie("text_value"));
So I am trying to get a user's first name so that I can display it on my chatting app. I have the user's information. I can get the user by playing around with res.render(). In jade I can do something like #{user.firstName} to have it printed out but I am not sure how I can use this data in jQuery.
Check if you can build an element as follwed:
case 1
<input id='user-first_name' type='hidden' value='#{user.firstName}' />
// Then you can use the value of input field as.
var firstName = $('#user-first_name').val()
case 2
you can directly write a script tag where you will initialize some window variables as :
<script>
window.user_first_name = #{user.firstName}
</script>
case 3
Also you can try assigning that value to data field of any html element(html tag) as followed :
<element data-first_name='#{user.firstName}'>
// Now you can use a jquery selector for selecting that element and you
// will be able to retrieve that value using data function
var firstName = $(element_selector).data('first_name');
I'm trying to pass the value of an input element from a form on my parent page to its child page. The form element on my opener page, as follows:
<input id="selectedOrgName" type="text" value="SOME_VALUE" name="selected_org_name">
The value of "SOME_VALUE" is dynamic and needs to be passed onto the child page. What I need to do is find that value by referencing the opener's input value.
I've tried a few things, mostly with basic JavaScript and have been unsuccessful -- so, I thought I'd try jQuery, but that is not working either. The code I've tried:
var abc = openerF.$("[name=selectedOrgName]");
Just do :
var selectedOrgNameValue = $("#selectedOrgName", window.opener.document).val();
Note that if you dont want / need to load jQuery in the child window, you can do :
var selectedOrgNameValue = window.opener.jQuery("#selectedOrgName").val();
I guys, I'm creating a VB.NET application, and this is the first time that I used Session Variables.
What I want to do is to pass the session variable from a page (first.aspx) to another page (second.aspx) via url.
Here an example of what I want to do:
In the first.aspx.vb page I declare a session variable and assign to it a value
Session("example") = "example123"
Then I pass this Session Variable to the first.aspx page
Response.Write(Session("example"))
and via javascript read the value of the Variable
<script type= text/javascript>
var SessionVar = '<%=Session("example")%>)';
</script>
Now, what I want to do is to change the value of the Variable (for example setting it as example456), and then pass the variable to the second.aspx [for example with window.open()] so that the url not contains the value of the variable but its name:
url/second.aspx?value=example AND NOT url/second.aspx?value=example456
Infact I don't want that the user read the value of the variable.
Finally I have to read the value of the session variable in the second.aspx.vb via Request.QueryString("value") and do the various operations.
Is it possible ?
If not, there is anothe way to do this
Thanks for the help :)
To set session variable from javascript can be done like below:
Create a hidden field control on the first page
<asp:HiddenField ID="HiddenField1" runat="server" />
Client script to set value of the hidden field
function setVal(value) {
// if using jQuery
$("#<%= HiddenField1.ClientID%>").val(value);
// if using javascript
var hf = document.getElementById("<%= HiddenField1.ClientID%>");
hf.value = value;
}
Create a button or link to navigate to the second page
<asp:Button ID="Button1" runat="server" Text="Go to second page" OnClick="NavigateToSecondPage" />
or
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="NavigateToSecondPage">Go to second page</asp:LinkButton>
In the first page code behind, create the NavigateToSecondPage sub to handle the onclick event of the button/link
Protected Sub NavigateToSecondPage(sender As Object, e As EventArgs)
Session("example") = HiddenField1.Value
Response.Redirect("SecondPage.aspx")
End Sub
Therefore, in your second page, you can access the Session("example") value and it will have a new value set by the client script in the first page.
Session variables are called this way because they are passed automatically from one page to the other within the same session, so you should just modify the value of the variable whenever you want and then access it again in the second page to find the value. You don't need to pass anything explicitely.