Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.