Repgahroll Posted December 3, 2009 Share Posted December 3, 2009 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. Link to comment https://forums.phpfreaks.com/topic/183875-get-elements-values-by-id-and-join-them-in-a-hidden-input/ Share on other sites More sharing options...
Tazz Posted December 3, 2009 Share Posted December 3, 2009 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> Link to comment https://forums.phpfreaks.com/topic/183875-get-elements-values-by-id-and-join-them-in-a-hidden-input/#findComment-970685 Share on other sites More sharing options...
Repgahroll Posted December 3, 2009 Author Share Posted December 3, 2009 Sweet! Thank you very much! Works like a charm! Link to comment https://forums.phpfreaks.com/topic/183875-get-elements-values-by-id-and-join-them-in-a-hidden-input/#findComment-970747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.