9

Since while I cannot set the value of an input field with type=text. Before, I always used something like this:

<input style="display: none" type="text" name="geo_poi" value="" id="geofeld" />

Then, in JavaScript i added code containing a line like this:

document.getElementById("geofeld").value = geo_poi;

This always worked. Maybe the new browsers don't want to support the method above anymore.

3
  • 2
    How come .value = "whatever" doesn't work for form elements? oO Commented Apr 19, 2013 at 9:59
  • 1
    what browser are you using ? Commented Apr 19, 2013 at 10:02
  • Chrome or Firefox, I also tested it in FireBug and in the console of chrome. But setAttribute("value", "anything") works as I supposed. Commented Apr 19, 2013 at 14:30

3 Answers 3

23

So using the following method for setting attributes worked fine.

document.getElementById("geofeld").setAttribute("value", geo_poi);
Sign up to request clarification or add additional context in comments.

Comments

2

For situations when setAttribute does not yield any result (think HTML5 user/password input), consider this:

document.getElementById("geofeld").setRangeText("text");

Comments

-2

HTML


<input type="text" placeholder="Item 1" id="item1" />
<input type="text" placeholder="Item 2" id="item2" />


JAVASCRIPT


$('#item1').blur(function() {
    var item1var = $('#item1').val();
    $('#item2').val(item1var);
});

Jsfiddle HERE

3 Comments

This does not look like "Javascript" to me. You might be using some library.
@engineerX Probably jQuery
so this is javascript right? <input type="text" onchange="passvalue()" placeholder="Item 1" id="item1" /> <input type="text" placeholder="Item 2" id="item2" /> <script> function passvalue() { var pValue = document.getElementById('item1').value; document.getElementById('item2').value = pValue; } </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.