Replace cookie value to space character using jQuery - javascript

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:'/'}));

Related

Dynamics 365. Field value (javascript)

How can I get field value in Dynamics 365 with JavaScript?
In browser console function Xrm.Page() return undefined.
And when I try get some attribute like a
Xrm.Page.getAttribute("new_city").getValue();
receive error in browser console:
Unable to get property 'getValue' of undefined or null reference
There are two ways you can approach this issue
In the 'target' dropdown in the top right corner of your Developer Tools window, switch to 'Client API Wrapper'. You should then be able to access the form with your javascript code. Your syntax is correct.
Append the beginning of your code with frames at index 0
example:
var city = frames[0].Xrm.Page.getAttribute('bah_city').getValue();
Good luck!
It seems that you havent select the right frame, in the upper left corner of the console you should changed to customScriptsFrame and execute you code
Hope it helps.
Regards
Xrm.Page() probably isnt a method that exists. Try Xrm.Page instead.
For Xrm.Page.getAttribute("new_city"), are you certain:
The field is on the form.
The field name is spelt correctly.
Your code:
Xrm.Page.getAttribute("new_city").getValue(); should work.
Make sure you are using the Name exactly as it is seen in the Field Properties.
Possible reasons are given in other answers.
To avoid errors, always use null check.
if(Xrm.Page.getAttribute("new_city") != null)
var city = Xrm.Page.getAttribute("new_city").getValue();
If you are using this field in header, then use this:
Xrm.Page.getAttribute("header_new_city").getValue();
If you are using this field in Business Process Flow, then use this:
Xrm.Page.getAttribute("header_process_new_city").getValue();

Setting an element value using HTML entities

I'm having an issue trying to set an input field's value when using HTML entities in that they are coming out literally as " rather than ".
Here is the code I am using:
document.getElementById('inputSurname').setAttribute('value', 'test"""');
in which the output is test""" though I want the output to be test""".
It doesn't look like a double-encoding issue since in the source code I am seeing it the same way I have set it here.
I know I could decode the value from its HTML entity format though this is something I want to avoid if possible for security.
Any help would be much appreciated :)
Try this:
document.getElementById('inputSurname').value = 'test"""';
Or if you want to keep &quot:
function myFunction() {
document.getElementById('myText').value = replaceQuot('test&quot&quot&quot');
}
function replaceQuot(string){
return string.replace('&quot', '""');
}
Or you can use escape characters.
document.getElementById("inputSurname").setAttribute("value", "test\"\"\"\"");
Well you could just write the new value as 'test"""'.
For other characters however, I'm going to refer you to this answer: HTML Entity Decode

jquery val not passing data

I've got several input fields and such jquery code:
jQuery(document).ready(function($){
$('input').change(function(){
var amount1=$('.product-addon-wesprzyj-autora input').val();
var amount2=$('#pa_kategoria-cenowa').val();
var amount3=$('.quantity .qty').val();
var fractal=0.01;
var Total=(amount1*amount2*fractal*amount3)+(' PLN');
$('.product-addon-kwota-dla-autora input').attr('value', Total);
});
});
Strange thing is that jquery code works. In real time in changes values in my inputs, BUT after clicking sumbit, value from '.product-addon-kwota-dla-autora input' seems to be empty in database. Why is that? is there any way of pushinig this code to work? If i will type via keyboard data into that field, everything works. ANy ideas what is here wrong?
With the code you provided, I am not quite sure what your problem is. It could be a problem in your server side code where you save the data to the table. You need to debug and that find out.
But make sure that you are setting the form values properly so that your server side code will have the correct data from the form. You may consider using the val() method to set value.
$('.product-addon-kwota-dla-autora input').val(Total);
Also , when you read values from form inputs and use it for numeric operations, Consider converting the type to a numeric version by using parseFloat() or parseInt()
var Total=parseFloat(amount1)*parseFloat(amount2)*parseFloat(fractal)
*parseFloat(amount3)+(' PLN');
Also, You may inspect your browser's network tab to see what data your browser is posting to the server code. That should help you to understand where your problem is.
it might me that your "Total" variable is empty. alert('Total') and check for result. if it shows some value then try to change your line from this
$('.product-addon-kwota-dla-autora input').attr('value', Total);
into this
$('.product-addon-kwota-dla-autora input').val(Total);

How to store html in hidden field using jquery?

How to store string with HTML tags in hidden field using jquery?
I am using the below code. But its not working.
var terms = $('#TermsAndCondition').val();
alert($('#hdnTerms').val(terms));
Here TermsAndCondition is TextArea and hdnTerms is hidden field.
In alert it returns the object.
use something like this
var value=$("input[type=hidden]").val();
alert(value);
You're just querying it wrong, try this
var terms = $('#TermsAndCondition').val();
alert($('#hdnTerms').val(terms).val()); //Note the extra .val() so you get the value
.val(terms) returns a jQuery object, not the value, you need to call .val() with no parameters to get a the value returned.
Assigning to .val() does not return the text (it returns a jQuery object), change your test to:
$('#hdnTerms').val(terms);
alert($('#hdnTerms').val());
To access the value you must call val() without parameters.
May I suggest you to simply use:
//hide terms when you don't need them
$("#TermsAndCondition").hide();
//show them again when you want
$("#TermsAndCondition").show();
not sure what you are trying to achieve there

saving value from form doesn't work

So, storing a Java String into a form hidden input value. I call said value via javascript and attempt to store it into a var. Strangely, I can display the value via alert but javascript crashes when I try to save it into a var.
The first line is from the initializing jsp file. It does some stuff that gets the string. The string is a list of ints that I plan on splitting in javascript for some stuff.
"<form id = \"listArrForm\"> <input id = \"listArr\" value = "+ output +" type = \"hidden\"></form>"
var listArr = document.getElementById("listArr").value; //Does work
alert(document.getElementById("listArr").value); //Does work
So yea, I'm guessing it has to do with the the type of value being retrieved?
Well, both should work as you can see in this jsfiddle: http://jsfiddle.net/2eWja/
What are you storing in the value that makes the script not work? Are you sure you're not putting quotes in?
what browser are you using? There could be problem for some
Btw using getElementById is known to be wrong. ;)

Categories