Input field wouldn't get the updated value - javascript

I have an input field with id Email and im getting the value of this field to update my object. However when i try to edit it again without a refresh and try to send it via Ajax, email field becomes empty. I get this field by using $("#Email").val() and I tried using .attr("value") as well however this gets the old value of the field not the new value.
My problem is similar to this "jQuery showing empty string on input text?" however, I can't use the solution there as I have to use the input box multiple times after updating.

However when i try to edit it again without a refresh and try to send it via Ajax, email field becomes empty.
Are you sure the page is not refreshing? The field can only become empty from either a refresh, or actual JavaScript code you have written/included that is causing the problem.
$("#Email").val() will read the value and will not blank it out.
.attr("value") will read what the value was when the page loaded, but not accounting for changes made by the user.
My problem is similar to this "jQuery showing empty string on input text?" however, I can't use the solution there as I have to use the input box multiple times after updating.
Do you understand the reason for that solution? The problem there was that the value was captured to a variable Name too early. The solution was to move the call to val() to later. (after blur took effect, not before)
I hope these are helpful, but there's really not much more I could tell you without seeing your code.
I expect this question to be closed due to lack of details. When you post the new question, please try to fix one problem at a time (either "becomes empty", or "gets old value") and post enough details for a solution. (i.e. an SSCCE)

Related

Cant seem to get value of input text fields value into hidden form fields using javascript

So I have a fiddle of the code:
http://codepen.io/databaseindays/pen/JGdgq
The idea is that the user can find their coordinates and then submit them via POST variables in hidden fields in the form.
Im using JQuery to simply read the lat and lang fields value into the hidden fields. But the POST variables are always empty. The values are not being copied.
One theory is that I have the hidden fields inside a FORM, while the inputs im trying to copy are not. So first question is, is that a scope issue? If so, should I omit the Form and submit another way, if that will give me access to the values?
Thanks
Norman
OK, you're probably going to kick yourself when you see this. I know it took me a few minutes before I noticed.
It looks as if you're trying to copy the value in the jQuery block at the bottom of the page. However, that bit of code is only running when the document is ready, and NOT when the geocoding operation takes place.

How to get a vaue of a notes text field in formula language?

I have a form on which there is a text field called "Role". Onload of this form i am assigning a value to this field using javascript:
document.forms(0).Role.value=top.parent.document.all.strRole.value;
When the form opens, the required value is getting displayed in the field Role but when i try to assign the value of this field in formula language in another field on the same form it gives me blank value:
test := #GetField("Role");
The value of test comes as blank.
Can anybody tell me why this is happening? Do i have to save the form before accessing the value?
Based on the comments you added, I believe you are trying to do something that is impossible.
A computed for display field is computed on the server, before the page data is sent to the browser.
The onload event script is executed in the browser, after the page data has been fully sent and loaded.
Since your formula `test := #GetField("Role"); executes in a computed for display field, it is clear that the onload script that sets the Role field's value has not executed yet, therefore it is correctly returning blank.
Try:
test := #GetField("Role");
First of all, when you are talking about "Role", ar you talking about Notes user roles, as defined in the ACL? Second, is this a Notes client application or a web (browser) application?
If it is a web application, the computed field will be computed first, and then, after the page is done loading, the Role field is populated.
Why are you mixing Formula and Javascript? The JS code could as well be done in Formula, then I am sure it would work.
Could you describe what you are trying to do in a little more detail? Where do the roles come from?

Strange javascript/jquery issue

Hopefully someone can help me here.
I have a page that displays a list of users in a modal popup. This page can be accessed in two ways, one way you choose Unapproved users and it will open the page, the other way you choose user accounts which will open a popup asking if you have any search criteria such as name, once you have finished there you search and it brings up the page of users.
I have a button on the form to clear any filters. When i run it on the Unapproved users page, it clears the box fine, however if i do it on the form from the other way the code will not empty the textbox and when i try an alert it shows no data. Where as the alert works on the Unapproved route!
Here is the jquery that i am using:
clear: function () {
//reset filters//
$('.usersFilterList li').remove();
$('.userFilterSelect option').show();
$('#UserFilter_SearchTermIncluded').attr('value', ''); // This line doesn't seem to work properly
alert($('#UserFilter_SearchTermIncluded').attr('value'));
//hide filter options
MSG.showNHide('', '#usersFilterBox');
//reset modal control buttons
$('#usersButSaveFilter,#usersButClearFilter').hide();
$('#usersButFilter').fadeIn();
usersFilter.refresh(0);
}
Can anyone see if i am doing anything stupid? As i say, it is exactly the same form called from the same MVC action just with the other popup in between.
Apologies if this is confusing, I cannot post anymore code i am afraid. I can assure you that the ID of the textbox is correct though.
Any advice here would be much appreciated as I have been staring at it for hours now...
Cheers,
Gareth
If i right click the second option and run in new tab and run that first pop up as a full page the code will then work! So the problem appears to be that there are two popups.
SOLVED
I found a work around of my own, thanks for all your help.
I simply assigned a class and searched for any items with that class and cleared it like so:
$('.jq-clearme').val('');
I will close this when i can. I am not allowed yet due to my rep being too low.
To change the value of an element (or to retrieve it), accessing the attribute is the wrong way to go - it's not synchronized in both directions. What you want is the property. While also exposed through .prop('value'[, newvalue]) the correct way to get/set it with jQuery is .val([newvalue]).
To clear the element's value use the following:
$('#UserFilter_SearchTermIncluded').val('');
To retrieve/show it, use
alert($('#UserFilter_SearchTermIncluded').val());
You should use val() to get/set the value of the input.
Use without a parameter to get the value:
$('#UserFilter_SearchTermIncluded').val();
And with a paramater set the value, in this case set it to nothing:
$('#UserFilter_SearchTermIncluded').val('');
Is there an ajax call involved which might be loading the Javascript you posted twice and hence when called the second time (after the ajax call) it finds a conflict?
As mentioned by others best to use .val('') to set a value and .val() to get the value. Check in firebug if there are any Javascript errors.
I found a work around of my own, thanks for all your help.
I simply assigned a class and searched for any items with that class and cleared it like so:
$('.jq-clearme').val('');
I will close this when i can. I am not allowed yet due to my rep being too low.

Read only textfield editable via inserted javascript?

I have a form with a read only field for display/submit to the next page purposes.
However, I noticed using developer tools in Chrome, I was able to add an id to an element, use the javascript console to select that element, and change its value. I submitted the form and what do you know - the next page acted on it as if it was the original value.
Now, there shouldn't be any problem with the people using the site I'm building, but it seems like a huge security flaw to me. Isn't the point of read-only to remain constant? If a savvy user to change it around, doesn't that pose a big problem? In fact, I didn't even think you could add and change attributes in chrome.
Please post your thoughts below, and let me know if there's a solution ("disabled" textfield, but setting the disabled property doesn't send the data to the next page).
NEVER trust input from a web form.
The user could, just as easily, remove the readonly attribute and edit the value. The readonly attribute is only something to help the user when filling out the form, so they don't edit a value expecting it to change, when your server actually won't let it be changed. So, always remember to code the behavior on your server first, and have the HTML form be a helpful guide for users to make the form easier to fill out (without having to submit the form several times to get relevant error messages).
To overcome this, if something is readonly and you do not want it edited, you could store the value in your database. Also, values provided by users should always be checked (and sanitized) as no amount of JavaScript, HTML, or CSS is going to prevent someone who knows what they're doing from adding new or changing/removing existing values.

HiddenField value modified by javascript is not posted back

This is weird, but I've been using this method all over my code: I have dropdown lists that I populate client-side, using callbacks and because of this I'm unable to access their selected values from code behind and using a hidden field to store selected value in it. I had no problem retrieving the hidden field's value on postback, but all of a sudden it stopped working and is always blank, even when the value on client side is present.
Any thoughts?
P.S. I'm not setting or resetting hidden fields on postback.
Okay, if someone wonders what's wrong: it seems there's something related to jQuery.
The thing is that DropDownLists and the hidden field, along with the button that causes postback are inside a jQuery UI dialog that is initiated on page load without opening and appended to the form. Besides this dialog i'm initializin another one and also appending to the form, but for some reason the first appended dialog exibits the weird behavior when postback works, but hidden field does not retain the value. If i don't append the second dialog to the form, everything works as expected. Can't really tell what might appending the second dialog be doing that is causing this weird behavior.
P.S if i reverse the order in which those two dialog boxes are appended, it works just fine... Weird!
Using .NET?
When the values are added dynamically the backend has no clue. You need to use Request.Form to get the values posted back just like oldschool ASP days.

Categories

Resources