I want to get the value of disabled text box in our next jsp but i am getting null value - html

I want to get the value of disabled text box in our next jsp but I am getting a NULL value.
Any idea what might be going wrong?.

Input fields marked with disabled="disabled" never send their value to the server when the form is posted. You could use the readonly="readonly" attribute in order to still make the field not editable by the user but send the initial value to the server when the form is submitted.

You can't get disable property value into server side. You need to run javascript to fetch disabled value into servlet.

Related

What is the correct and most safe way to check if HTML form checkboxes and such have been POST-set?

This has confused me since the early days. Maybe it's just in my head, but it seems to me as if this has varied over time, between browsers, and possibly even depending on the local language/locale.
Basically, whenever I need to check if a HTML input of type "radio" or "checkbox" has been set, I always do:
if (isset($_POST['the_name']) && trim($_POST['the_name']))
// do stuff
This just makes sure that the POST variable is sent whatsoever (which in itself doesn't mean that it was actually checked/selected, as far as I can tell, since its "value" can be an empty string) and that it's something other than '' (empty string). It seems like this has worked for a long time, but I have two problems with it:
It's ugly. I need to abstract it into a function, but then I want to know if it's a good idea in the first place, or wrong somehow.
It makes the assumption that any non-empty string value means "checked" or "selected", whereas the standard may say a specific string value such as "on", or maybe any number of such strings depending on the language/locale.
Are there cases where my above code falls apart? Do browsers ever submit POST forms where they include names which have no user input/selection in the HTTP request? Or does the existence of a name in the POST blob mean that that "field" has been actively changed/set/checked/selected?
The idea behind checkboxes is that the value is sent over to the server only if the checkbox was checked when submitting the form. The value can be anything, even an empty string. As long as the field is part of the transmitted form it means the box was ticked.
The value attribute is one which all <input>s share; however, it serves a special purpose for inputs of type checkbox: when a form is submitted, only checkboxes which are currently checked are submitted to the server, and the reported value is the value of the value attribute. If the value is not otherwise specified, it is the string on by default.
This means you could have a form like this:
<form action="" method="get">
<input type="checkbox" name="c1" value="">
<input type="submit" value="Send">
</form>
If the checkbox is not checked when submitting then $_GET will be an empty array.
If the checkbox is checked then the value of $_GET will be:
array('c1' => '');
To check whether the box was ticked when sending the form you only need isset()
if (isset($_POST['c1']) {
// The box was checked!
}
Sometimes you would like to assign a value attribute to your checkbox. In such situations you can use the shorthand operator for isset() function ??.
// Create a variable from the checkbox value or assign an empty string if the box was not checked
$nyCheckbox = $_POST['c1'] ?? '';

HTML checkbox default

I have an HTML checkbox:
<input name="foo" id="foo" type="checkbox" value="1" 𝙨𝙩𝙖𝙩𝙪𝙨/>
In my application, the checkbox should retain its checked status between form submits (method=GET), so my server-side code simply inserts the checked status flag if foo is found in the GET-data.
if "foo" in GET:
𝙨𝙩𝙖𝙩𝙪𝙨 = ' checked'
else:
𝙨𝙩𝙖𝙩𝙪𝙨 = ''
This is fine, and it works. However, the logic breaks down when I want the checkbox checked by default, because, from the server side, I am unable to differentiate between:
the checkbox being unchecked by the user ("foo" not in GET) – in which case I should leave the checkbox unchecked.
the user having visited the form for the first time and having not yet specified a value (also "foo" not in GET) – in which case I should check the checkbox by default.
I have considered using a hidden input that tells me whether this is a user-submit or not, but this messes up the URL since the data is passed in GET. I feel there should be a better way.
Assuming the server knows:
All the (checkbox)inputs
Which of these inputs are default checked
You can reverse the test:
Test all known server-side fields (loop server-side data to...)
See if they exist in the received data (... test client-data (every time))
If the are checked by default, and not in the data, you know the user unchecked it

Are HTML buttons with no values submitted in a form?

if you have
<button class="button yellow" type="submit"
name="button">Log in</button>
and you submit it, what gets posted to the server for the button which has a name but no value attribute?
The reason I ask is that I'm parsing HTML forms, and need to post the named values that send data to the server. I got the others covered, but wasn't sure about button.
According to the HTML Spec, a button's value is either determined by its value attribute or is an empty string. A button's value is only submitted with the form if the button has a name and is used to initiate form submission. If the button in your example is clicked, the resultant submission will be:
"button=" (quotes added)
Some browsers (mainly older IE versions) have incorrect implementations of this button behaviour that either set the value to the button's contents or submit all button values regardless of initiation source.
button does not get posted to server when the form is posted. Only input type's like text, password, select elements etc., which accepts user inputs will be posted to the server
Button never supplies value to form. It just provides a submit event that tells the browser to submit that form with all the input tags to the action attribute inside your form tag using the method attribute value. Button only provides the event and not the values.
There will be nothing posted to the server for buttons. When you click a button, it invokes the action of submit, that is all.
I tried it out by printing the request.POST in django.
This image shows a "Log in" button with no value but name="button", as asked
The console shows
< QueryDict: {u'csrfmiddlewaretoken': [u'9aAx..'], u'sensor': [u'sd1'], u'button':[u'']}>
So, in this case, the form is sent as a dictionary and for the buttons the key, value pair is "button" : " ". So, if you try to get value of this button with request.POST.get, you will get NULL.
So, the answer to your question is the form consolidates all the input values, which can be accessed with their 'name' including buttons. If no value is provided, it returns NULL.

Can't remove the value entered in the djFilteringSelect dojo control in xPages

I am using the djFilteringSelect control to show values in a dropdown as user type a value.
The lookup and typehead is working fine. The user type a letter and the dropdown allow the user to select a value which is then displayed in the dropdown field.
If the user now decide to remove the value first selected so that the combobox is empty and leave the field, then the first value in the list is now automatically filled in.
The consequence of this is that if the user have added a value there is no way to remove the value and leave the box emtpy.
I am using required=false for both the control and the dojo attribute but it does not seem to help. There are also a few other djFilteringSelect attributes I have tried like "Autocomplete" and "trim" but it does not work
Here is the code
<xe:djFilteringSelect id="test" type="select" store="jsondata" searchAttr="data" required="false" labelType="html" invalidMessage="Not valid">
<xe:this.dojoAttributes>
<xp:dojoAttribute name="required" value="false"></xp:dojoAttribute>
</xe:this.dojoAttributes>
</xe:djFilteringSelect>
Initally the field is not required, but if the user have entered a value it is required.
My question is if there a way to prevent the djFilteringSelect control to always populate the field if I have previously added a value
I found someone who solved this in another stack overflow topic, by creating an empty entry in my data store. but I could not get this to work
Dojo: Select of empty value for FilteringSelect while required=false
I do this quite a lot. Right now I don't have a working sample to show you (since I moved to bootstrap - and have to code the selects by manually adding select2 controls) but something like this should do it...
I add an "empty" value at the top of my select - and that seems to work no matter whether I am using a combobox, djCombobox or combobox with select2 from bootstrap. My markup typically looks like:
<xp:comboBox id="inputLocationSelector" value="#{User.catchListType}" disableClientSideValidation="true">
<xp:selectItem itemLabel="(none)" itemValue=""></xp:selectItem>
<xp:selectItems>
<xp:this.value><![CDATA[${Configuration.meta.listLocationTypeOptions}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
Then you could specify "(none)", "All" or " " for the "not-selected" value depending on your needs.
Validation is a different thing so just specifying "required=false" does not give you the "empty" value.
/John

HTML input field disable input but still POST

Basically i want a disable text field to show the value stored in a database but i don't want it to be editable by the user.
i've tried using disabled="disabled" but then it no longer POST to my form handler...
Any suggestions?
thanks
docu:
In this example, the INPUT element is
disabled. Therefore, it cannot receive
user input nor will its value be
submitted with the form.
why do you need the value? then try the readonly-attribute instead of disabled or go for another hiddenfield.
edit:
it's not fully clear to me, if you use asp.net, bu if so, you could just do
<form submitdisabledcontrols="true" runat="server">
you may give it a try :)
If you insist on using a disabled field, you can enable it during form submission by handling the form onsubmit event, where you will enable the field and submit the form.
A second option would be to use a readonly field which you may cleverly make look as disabled via CSS.
A third option would be to use a disabled and a hidden field. Rename your disabled field to something irrelevant and use the original field's name for the hidden one.
Take your pick.