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);
Related
EDIT:
So, after more playing the problem is a bit more complex than originally thought, and while I have found a workaround, I'm curious to figure out why this is happening, so here's the update:
I have created the following function to fill in form fields using HTML DOM:
function populateField(fieldname, value) {
document.getElementById(fieldname).value = value;
}
Then in the main part of my php code, I call that function and hand it the ID of the field, and the VALUE I want to set like this:
echo('<script>');
echo('populateField("contact", "'.$fillContact.'");');
echo('</script>');
This works perfectly fine for all my form fields except for the datetime-local field. It simply doesn't work.
So I decided to bypass my function, and just set the field directly in the main part of the code like this:
echo('document.getElementById("arrival").value = "'.$fillArrive.'";');
This works perfectly fine...but ONLY if I execute it before I call my function for the first time. In other words...
THIS works:
echo('<script>');
echo('document.getElementById("arrival").value = "'.$fillArrive.'";');
echo('populateField("contact", "'.$fillContact.'");');
echo('</script>');
but THIS does not work:
echo('<script>');
echo('populateField("contact", "'.$fillContact.'");');
echo('document.getElementById("arrival").value = "'.$fillArrive.'";');
echo('</script>');
For the life of me I can't figure out why it would make any difference at all, but there you have it. If anyone sees something that I'm missing, I would love to know what I'm doing wrong!
Thanks all!
ORIGINAL:
So this is an interesting one. I have an HTML form field with multiple fields, including a datetime-local field. Using Javascript I am able to access and/or change the value property of all of the other input fields using HTML DOM, but for some reason, I am unable to access or set the datetime-local value property. Trying to read the value of the field returns a value of "" and trying to set the value has no effect.
Interestingly, if I include the value="some datetime" into the HTML tag itself, it sets the value property correctly. Thinking the value="" may have been somehow mucking things up, I removed it, but there is no difference.
Here is the field code within the form:
<input type="datetime-local" name="arrival" id="arrival" value="'.date('Y-m-d').'T00:00">
That works correctly and sets the field to the current date with a time of 00:00:00.000.
But if I do something like this afterwords:
x = document.getElementById("arrival").value;
Then x = "";
Likewise, if I attempt to set the field by doing this:
document.getElementById("arrival").value = [some datetime value];
the field remains blank.
Obviously, I'm missing something here, but for the life of me I can't figure out what. I even went to lookup an example. This example works fine, but even copying the lines it still doesn't work in my code:
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_datetime-local_value
Ideas?
I'm afraid your value for date is not in correct format. You need to have ISO-8601 formated date as mozilla references it in online docs here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
var dateControl = document.querySelector('input[type="datetime-local"]');
dateControl.value = '2017-06-01T08:30';
Also, if you not set value and try to console it, it's empty as expected, and after you set it, it yields same date in ISO format.
GL
function myFunction() {
console.log( document.getElementById("myLocalDate").value )
}
Date: <input type="datetime-local" id="myLocalDate" value="">
<button onclick="myFunction()">Console date</button>
I'm new to JavaScript and JQuery, but I've been able to get around and it's been fun. I came across something at work, however, that is boggling my mind. And it's not something I really know how to explain either, so I attached a screenshot.
I have this function (there are a few variables that I have access to such as $formItem, $request, $object, $jQuery, $widgetId, $ajaxUrl, and params, that are given to me):
<input type="hidden" name="SomeRandomName" id="SomeRandomId" value="Hello"/>
function reload(element) {
var result = $request.getParameter("SomeRandomId");
console.log("Result");
console.log(result);
}
When I load the page, I get this issue.
https://i.imgur.com/aASflls.png
It seems the value is being written directly into the code? If I try to wrap the result in strings or append it, I get an error saying it's not possible. What can I do in this situation?
Let me know if you need anything else. This is the first time I've encountered this problem.
I've tried using jQuery, but the data disappears when the form is submitted and that is an issue at work. We need the data to persist when the form is submitted and bounced back. The process we do that in is by calling $request and assigning a velocity variable the data. I could not do this procedure in this case because I am dynamically re-assigning HTML elements their original value.
When you are assigning result to 'Hello' in console it should be in single quotes as it's a string. Should be let result = 'Hello'.
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();
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. ;)
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:'/'}));