views:

62

answers:

4

I want to disable an input field, but when I submit the form it should still pass the value.

Use case: I am trying to get latitude and longitude from Google Maps and wanna display it, but I don't want the user to edit it.

Is this possible?

+1  A: 

Input elements have a property called disabled. When the form submits, just run some code like this:

var myInput = document.getElementById('myInput');
myInput.disabled = true;
nickf
+1  A: 
<input id="field-id" type="text" disabled="disabled" />

or with jQuery

$('#field-id').attr('disabled', 'disabled');
Saul
+4  A: 

I wanna Disable an Input Field on a form and when i submit the form the values from the disabled form is not submitted.

Use Case: i am trying to get Lat Lng from Google Map and wanna Display it.. but dont want the user to edit it.

You can use the readonly property in your input field

<input type="text" readonly="readonly" />
Sarfraz
This will not disable the field as he wants (the value will still be passed)
Pekka
@Pekka: That I *think* what he wants. When he makes it disabled, values doesn't pass but with readonly, he can prevent it from editing and the value will still be passed.
Sarfraz
@Sarfraz ah, fair enough. It could be both ways, true.
Pekka
Sarfraz is right. i dont want the input field editable but be passed :D
Harsha M V
@Hansha M V: To contrast one part of a sentence against another in English, use "but" instead of "and". People misunderstood you because of improper grammar - the meaning of your text suggests that the passing of a variable is a problem while in reality it was a goal.
Saul
@Saul :D yeah. didnt read it after right to check... sorry about it :D
Harsha M V
+1  A: 

you can also use the Readonly attribute: the input is not gonna be grayed but it won't be editable

<input type="text" name="lat" value="22.2222" readonly="readonly" />
Darkxes
thank you :D for the explanation
Harsha M V