Enabling a Textbox and making it editable - javascript

I have a textbox field displayed in my jsp file which looks always disabled and uneditable. I would like to have it enabled and editable on one condition.
So when the above condition is satisfied, I will save the page which save this field in DB. I would just like to have the text box enabled and the field editable. My code is as follows,
<li class="Textbox"><input type="text"
dojoType="dijit.form.NumberTextBox" name="field name"
id="EDIT21" style="width: 45px;" size="4" maxlength="3"
value="${value of an expression}"
onchange="Config1.updateStatus();" required="true"
constraints="{min:1,max:999}"
rangeMessage="<spring:message code='validation.' arguments='1,999' />" />
</li>

There's nothing in that code that would cause the textbox to behave like that. It sounds like you've either got some javascript disabling the textbox, or some CSS that makes it appear as though it's disabled even though it's not. If it's Javascript, look for a line that sets the disabled property, such as
document.getElementById('EDIT21').disabled = true;
or
document.getElementbyId('EDIT21').contentEditable = false;

Related

How can i create HTML5 like required alert for radio button?

For the input type text, if i add required attribute, my form won't submit and browser will focus on required field and alert will say please fill this field.
For the input type radio, if i add required attibute, my form won't submit but also it does not provide me any alert or focus on the radio which is unchecked.
If this is not an in-built functionality for HTML5, can i in some way create it and make it look like the same as it looks for text inputs so that style integrity is also preserved?
This code works well, if you not select radio, form will not submit. If you select one and enter text in textbox, form will submit.
<form>
<input type="radio" name="one" value="1" required>
<input type="radio" name="one" value="2" required>
<input type="radio" name="one" value="3" required>
<input type="text" name="two" required>
<button>Submit</button>
<form>
Checked on latest version of Google Chrome. May be you found a bug in your browser, try to update it.
Beside required radio button alerts work "perfectly fine" in Chrome...
jsBin demo
it makes no sense at all to have an alert for a radio button, that's silly.
If you have a radio button:
there's absolutely no need to have only one radio button. → Use checkboxes.
there's absolutely no reason to have all radio buttons unchecked initially.
one must be checked by default - and it's your job to do so
logically there's no need to popup alerts like "This radio button is required" - therefore neither to set a required attribute to a radio button.
if you still don't understand why... well simple because radios are used as UI switch states. Only one can and must be checked. If you make them all initially unchecked - and a client unintentionally hits a radio - he's dead in the devil's loop, because once you enter the circle there's no way out. Therefore makes no sense to have all blanks in the first place. You cannot undo... (well, unless you have another silly checkbox or something that says "uncheck all radio buttons!" nonsense).

Copy input field from one to another?

UPDATE: I got in contact with the developer and he said to use this code as a foundation:
(function($) {
$('.jr-page').on('keyup','.jrAutoSuggest',function(){
$(".customfield").val($(this).val());
});
})(jQuery);
It doesn't work at the moment and I'm not sure why but you can also see my original post below this text for more details and I appreciate all of your help:
I am trying to copy one input field to another when a user types. I would like to accomplish something like this: http://jsfiddle.net/bxHQ5/ Notice that when you type into the input box on the left, it duplicates the text on the right.
To be more specific, on my website, I am using this form
I want what the user types in the "Car Manufacturer" input box to directly be copied to the "Testfield" input box as they type. Also, the "Testfield" input box text cannot be deleted or altered by the user once text is inputted in the car manufacturer field. They both have to be exactly the same.
Please note that the car manufacturer input field shows a hidden input which the user cannot see and should be ignored in this case. If you look at the HTML, the car manufacturer input looks like this:
<input id="myrelatedfield" class="jrAutoSuggest ui-autocomplete-input acInstructions" type="text" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"></input>
You'll notice I put my own customer ID in there called "myrelatedfield" The field it needs to copy text to looks like this which has a custom class "jr_testfield"...
<input class="jr_testfield jrText" type="text" data-click2add="0" name="data[Field][Listing][jr_testfield]"></input>
Thanks!
I ave updated the code
have a look at it
http://jsfiddle.net/vishalgupta358/bxHQ5/383/
$("#EmailAddress").keyup(function(){
$("#Username").val($(this).val());
});
Use readonly="true" property to prevent write access.Input value will also be available when u submit the form
HTML:
<input type="text"id="EmailAddress" name="EmailAddress" value="" >
<input type="text" id="Username" readonly="true" name="Username" value="">
Script:
$("#EmailAddress").keyup(function(){
$("#Username").val($(this).val());
});
DEMO

ASP.NET Detect if Javascript disabled field

I am hoping there is an answer for this...
Setup:
Pretty complex ASP.NET Application doing a bunch of user interaction, some of which requires that Javascript disables some fields when others are clicked (had to do it in Javascript, b/c the postback issues in ASP.NET made it impossible, so had to it client side).
That code is all well where Javascript does the classic
document.getElementById(currObj).disabled = true;
The problem:
When I am ready to submit the page, how can I make ASP.NET (C#) notice if a field (Textbox or Radio box) has been disabled client side, so it does NOT submit that field in the form?
Is this even possible?
Much thanks in advance!
Any disabled fields don't submit but normal and even hidden ones do. This is how disabled fields work.
<input type="text" name="Test_1" value="off" disabled="disabled" />
<input type="text" name="Test_2" value="on" />
<input type="hidden" name="Hidden_1" value="hide_off" disabled="disabled" />
<input type="hidden" name="Hidden_2" value="hide" />
In the example only Test_2 and Hidden_2 will submit because the others are disabled.
You can see it at work in this jsfiddle: http://jsfiddle.net/bJ7Rq
The only way ASP.NET knows that a control has been disabled is if it was disabled from .NET and the Enabled = false property has been written to ViewState. When you disable a field on the client-side, this isn't the case, so ASP.NET will retain the default Enabled value.
As previous commenters have mentioned, the value of a disabled field will be completely excluded from the POST body sent to the server on postback. In the case of a basic TextBox on a page, that would mean the Text property would revert to String.Empty. To differentiate between an empty string in an enabled field and an actual disabled field, I think you'd need to look directly at the Request.Form object to see if the key exists. For example, if I had a TextBox named myTextBox on a blank page, Request.Form["myTextBox"] would be null for a disabled field. For an enabled field, it'd be whatever string value the field contained, including String.Empty if it were blank. Of course, if the control is in a naming container (e.g., a ContentPlaceholder or something) that messes with the name property on the actual field in HTML, you'd need to use the full HTML name.
So for example:
bool fieldIsEnabled = Request.Form["myTextBox"] == null;
It's not elegant, but it should get the job done (excluding checkboxes, which would also be null if the box wasn't checked).

Options added to [disabled multi] Select field dynamically are not posted?

I have dynamically created option elements with javascript. I double click an option from one select field to transfer it to a second, disabled, multiple select field. This works fine. The problem appears when I go to submit the form with the new information. The second select field is not passed to PHP. I'm assuming it thinks its empty, but each of the options I added are selected by default and I visually see them all there. I've been looking around for a solution to this, but am having little luck. Everything I can find says that the most likely cuprit is a browser incompatibility or that the elements are not being added to the form. If it is a browser incompatibility issue, I've tried it on all the major browsers all with the same results, so I would like to know which one I'm missing (FF, Chrome, IE). As for not being added to the form, I don't see how that could be possible. The select element already exists in the form and I am merely appending new options in it. Am I missing something, or is this just not possible?
<script type="text/javascript" language="JavaScript">
function addModule(value, title) {
modules = document.getElementById('modules');
modules.options[modules.options.length] = new Option(title, value, true);
}
</script>
<form name="addModules" method="POST" action="submit.php">
<select name="moduleList" size="20" ondblclick="addModule(this.options[this.selectedIndex].text, this.value);">
<?php //dynamically created options from PHP ?>
</select>
<select id="modules" name="modules[]" multiple="multiple" size="20" DISABLED></select>
<input type="submit" value="Add Modules" />
</form>
Disabled fields are not submitted. The easiest solution is to change it to readonly. If you're determined to have it as disabled, you could make a hidden field that is updated with values from it, but I strongly suggest just using readonly and then trying to style it as desired.
It's because the second select is disabled, it's data doesn't get sent when the form is submitted.
You could try making it readonly instead of disabled.
This is the standard browser behavior. While adding the values to the disabled select list, you can also add it to a hidden input field, and then access this in the posted request.

input type disabled and readonly behave differently with a href

I have below code where i disable and enable a calendar clickable icon.
<p>
<label>
<input type="text" name="date18" id="date18" value="01/01/2012"
style="width:75px;" disabled/>
</label>
<a href="#" onclick="somecaledarrelatedstuff()" name="calid" id="calid">
<img src="icon-Calendar.jpg" alt="Click to pick a date from a popup
calendar"/>
</a>
</p>
When I add disable as above both the input field and the link to the calendar popup are disabled as well. But because the values of disabled elements are not submitted, I thought of making it read-only. However, the problem is that when it's read-only, only the input field is getting read only (not also the calendar pop up link) too, like using disable.
I know if I want to disable (just to prevent the user from editing) both input field and href I can use disabled and have a hidden input variable, and submit it and refer to that variable. But I was looking for an alternative way because I will have a lot of refactoring to do to my code if I introduce a new hidden variable.
Thanks.
If you want the input field to be disabled but still send its value upon submission of the form, you can use bit of JavaScript for that.
To achieve this, first add this bit to the <form> tag:
<form ... onsubmit="EnableInputs(this);">
Then add this JS function:
function EnableInputs(oForm) {
oForm.elements["calid"].disabled = false;
}
You can enable more elements like this, or all inputs using getElementsByTagName and looping over it.
This will just enable the element when submitting thus send its value.
Disabled does not submit values, but read-only does submit values.

Categories

Resources