I have this:
<div id="atc_images"></div>
<textarea id="img" style="display:none" rows="30" cols="30" name="cur_image"></textarea>
<input name="invia" type="submit" value="Invia" onclick="document.getElementById('img').innerHTML = getElementById('atc_images').innerHTML";>
So I send to submit.php
the content that will be generating inside <div id="atc_images"></div>
How can I pass multiple getElementById
all at one time when <input type="submit"..>
is clicked?
I want something like this:
<input name="invia" type="submit" value="Invia" onclick="document.getElementById('img').innerHTML = getElementById('atc_images').innerHTML && document.getElementById('title').innerHTML = getElementById('title_inside_another_div').innerHTML";>
I have this:
<div id="atc_images"></div>
<textarea id="img" style="display:none" rows="30" cols="30" name="cur_image"></textarea>
<input name="invia" type="submit" value="Invia" onclick="document.getElementById('img').innerHTML = getElementById('atc_images').innerHTML";>
So I send to submit.php
the content that will be generating inside <div id="atc_images"></div>
How can I pass multiple getElementById
all at one time when <input type="submit"..>
is clicked?
I want something like this:
<input name="invia" type="submit" value="Invia" onclick="document.getElementById('img').innerHTML = getElementById('atc_images').innerHTML && document.getElementById('title').innerHTML = getElementById('title_inside_another_div').innerHTML";>
getElementById
only selects the first instance of the element with the corresponding ID, i suggest you use document.getElementsByClassName("classname")
and loop through it
– Yusaf Khaliq
Commented
Jan 21, 2013 at 15:47
You just add both statements into the onclick parameter, separated by a semi-colon, just as you would in a SCRIPT block. Remember to use document.getElementById
, not just getElementById
.
<input name="invia" type="submit" value="Invia" onclick="document.getElementById('img').innerHTML = document.getElementById('atc_images').innerHTML; document.getElementById('title').innerHTML = document.getElementById('title_inside_another_div').innerHTML";>
Try using a semi-colon instead of '&&'
IDs need to be unique for elements, thus it's best to name the elements what you want to send via its class name. Then use document.getElementsByClassName("class").
Also make sure your target browser works with it, nothing IE 8 or below works: http://caniuse./getelementsbyclassname