Jump to content

Get elements values by ID and join them in a hidden input.


Repgahroll

Recommended Posts

Hello.

I need a function that gets inputs values by fields IDs and join them on a hidden field.

 

Something like:

 

function text() {
document.form.hidden.value = document.form.elements['one'].value+document.form.elements['two'].value;
}

inputs:

<input type="hidden" name="hidden">
<input type="text" id="one">
<input type="text" id="two">

 

In this case the value of hidden field should be the values of (id)one plus (id)two.

However, the above code only work on ONE browser, and i want a little bit more compatibility. I think the right way to do is using getElementById, but i don't know how to make it work.

 

Thank you in advance.

Try this:

 

<input type="hidden" name="hidden" id="hidden">
<input type="text" value="hello" id="one">
<input type="text" value="world" id="two">

<script>
    function concatenate()
    {
        string = document.getElementById('one').value + ' ' + document.getElementById('two').value;
        document.getElementById('hidden').value = string;
    }
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.