Home > DeveloperSection > Forums > Multiple ids with getElementById();
Ankit Singh

Total Post:341

Posted on    August-19-2013 12:39 AM

 JavaScript JavaScript 

 1 Reply(s)
 3017  View(s)
Rate this:
Hi Developers!

I'm trying to get javascript to write html on a page when a link is clicked.

function updatetext(){

    var file = document.getElementById("file").value;

document.getElementById('updated').innerHTML = file;


<input id="file" value="text I want to write to the page" type="hidden">

<span id="updated">&nbsp;</span>

This works for an ID labeled "file" but I have multiple ID's like, file1, file2, file3...

I'm wondering if my onclick="updatetext()"; should have some argument like onclick="updatetext(1)"; but that doesn't seem to work. I'm not sure how to get the right input id from clicking on the link.

thanks in advance

shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Posted on    August-19-2013 8:37 AM

try this,it may  may be resolve your problem
function updatetext(id){

    var file = document.getElementById("file" + id).value;

    document.getElementById('updated').innerHTML = file;


That should do it, if you want to do what I interpreted

Don't want to miss updates? Please click the below button!

Follow MindStick