I have this line in the header of my JSP <script>var logicalName = "${logicalName}"</script> which is resolving to the correct value.
I want to access this value via javascript/jquery. How do I do this?
This is not working console.log($logicalName);
You just need to remove the string symbol from your parameter
console.log(logicalName);
console.log("${logicalName}");
and
console.log(logicalName);
Both will work!
Related
i want to add the value of my function to the variable.
for example i have something like this
<input v-model="search.steering" #input="onChange('steering')"/>
that mean i want to insert the steering each i input the text.
here the function
onChange(typemember) {
this.search.typemember
}
what im doing here is i add the typemember value to this.search variable.
so the variable in javascript now will be like this this.search.typemember the typemember value is taken from #input="onChange('steering')"
in this example the variable now will be like this this.search.steering. is that posible? or is there anothere way to doing this?
btw im using vue here.
To access this.search.steering dynamically using typemember you'd just need to use square brackets:
this.search[typemember]
Is there any way that i can get a variable that i've declared in JavaScript Function to the JSTL tags ?
Javascript
var abc = document.getElementById('asdf').value;
here is the JSP:
<input type="hidden" id="asdf" value="onetwothree" />
and i want to declare the C:set from the JavaScript
<c:set var="ex" value="${abc}" />
The purpose it to get "ex" variable with the value "onetwothree".
Sorry for the rough explanation. Thanks
you are doing it other way. it is possible to access a variable declared in jsp from javascript using below code
<c:set var="ex" value="test" />
<script type="text/javascript">
var abc = '${ex}';
</script>
but other way around as you mentioned above is not possible
If you are looking to modify DOM based on what is provided in input box then I would suggest to use code like below (in javascript)
var abc = document.getElementById('asdf').value;
// assuming you want to print this value in a label
document.getElementById('mylabel').innerHTML = abc;
In short if you want to do any change in DOM based on client input, do it through javascript instead of relying on JSP
You can't access JSTL tags from Javascript, simply because those tag exists only server side (client side they are replaced by plain HTML).
You can always send the javascript var as request parameter, then use it server side.
the following is my cshtml code inside durandal application
<script type="text/javascript" src="~/Scripts/require.js"
id="countryscript" data-main="**here i have to set value**"></script>
I want to set script attribute data-main with my javascript variable value. How to achieve this ?
I tried as
document.getElementById("countryscript").data-main = countrycode;
its showing syntax error near = sign. Need help..
Try this:
document.getElementById("countryscript").setAttribute("data-main", countrycode);
Taken from MDN
var d = document.getElementById("countryscript");
d.setAttribute("data-main", countrycod);
Or if you have JQuery, this is much easier
$('#countryscript').attr("data-main", countrycod);
I know there is already questions about that, but I just canĀ“t simply get this work, I have a JSP file with a java variable in it:
String test = "Hello";
And I need to read this value in the Javascript embedded in the same JSP file, I tried so many options, but it is not working, and for security I don't want pass the value using the URL or hidden values.
Any ideas of how get this working?
The best way to do it is to use something like following in your javascript code;
var myvar = '${jspvar}';
I know this one is old, but this worked for me:
var javaScriptVar="<%out.print(javaString);%>";
you need to make sure that if you are using an external js file (out of the jsp file), the above line has to be before the "include" script tag. for example this is the jsp file:
var javaScriptVar="<%out.print(javaString);%>";
<script src="some_location/test.js"></script>
You can pass the value by calling some methods in html part..
<input type="submit" value="view" onclick="callpro('<%= varname %>')" />
var jsvariable="<%=test%>";
One thing to note is that you could namespace those variables in this way:
var MYAPP.javaScriptVar="<%out.print(javaString);%>";
The technique is from "Javascript: The Good Parts" Book.
I have stored some textbox values in cookies.
But if textbox blank then cookie value will "null"
I am assigning that cookie value to another textbox.But due to the null value of cookie it showing me "null" in textbox.
I want to replace "null" with a blank space.
Make uf of .val() function will do you task.
$('#youtextboxid').val(valueneedtoset);
Try with
$('input[name="Custom_Field_Custom7"]').val('11111');
It's hard to tell based on what you've said, but I think the problem might be that you are trying to access the textbox before it has loaded. Try something like this:
$(function() {
// your code here
});
And as others have mentioned, it would be a lot easier to just do this:
$('input[name="Orders\\.Custom_Field_Custom1"]').val($.cookie('UploadFile',{ path:'/'}));