Note that there are some explanatory texts on larger screens.

plurals
  1. POobtain data from html elements and populate others with the info
    primarykey
    data
    text
    <p>I'm currently working on an AJAX-based function to load a youtube video into an existing div. That part is working nicely. </p> <p>Now I want to modify my code so that I can also grab a hidden title and description for each video and add this data above and below the video (title should be above, and description should be below the youtube video).</p> <p>The problem is I am not sure who to achieve this modification. here is what I have so far:</p> <p>My Javascript:</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; function SendValue(v) { xmlHttpReq = new XMLHttpRequest(); xmlHttpReq.onreadystatechange = HandleValue; xmlHttpReq.open("GET", "srcsendback2.php?code="+v,true); xmlHttpReq.send(); } function HandleValue(Code) { if(xmlHttpReq.readyState == 4) { if(xmlHttpReq.status == 200) { var Code; var CodeTitle; var CodeDesc; var Code = xmlHttpReq.responseText; CodeTitle = code + "-title"; CodeDesc = code + "-desc"; document.getElementById('vidtitle').innerHTML = document.getElementsByClassName('CodeTitle').innerHTML document.getElementById('viddesc').innerHTML = document.getElementsByClassName('CodeDesc').innerHTML document.getElementById('ytvid').src = document.getElementsByClassName('Code')[0].getElementsByTagName('a')[0].href window.scroll(0,0); // horizontal and vertical scroll targets, scrolls page to the top } } &lt;/script&gt; </code></pre> <p>And here is some example html:</p> <pre><code> &lt;h1 id="vidtitle"&gt;&lt;/h1&gt; &lt;div id="videoDiv"&gt; &lt;iframe id="ytvid" width="500" height="300" frameborder="0" src="http://www.youtube.com/embed/xyz" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt; &lt;/div&gt; &lt;p id="viddesc"&gt;&lt;/p&gt; &lt;div id="links"&gt; &lt;button type="button" name="button" onClick="SendValue('abc')" value="http://www.youtube.com/embed/123"&gt;Title 1&lt;/button&gt; &lt;br /&gt; &lt;button type="button" name="button" onClick="SendValue('def')" value="http://www.youtube.com/embed/456"&gt; Title 2&lt;/button&gt; &lt;br /&gt; &lt;button type="button" name="button" onClick="SendValue('ghi')" value="http://www.youtube.com/embed/789"&gt;Title 3&lt;/button&gt; &lt;br /&gt; &lt;div id="content" style="display:none;"&gt; &lt;ul class="media-collection"&gt; &lt;li&gt; &lt;div class="m-left"&gt; &lt;a href="#"&gt; &lt;/div&gt; &lt;div class="m-right"&gt; &lt;p class="CodeTitle"&gt; &lt;a href="http://www.youtube.com/embed/123"&gt; &lt;span class="field-content"&gt;Title 1&lt;/span&gt; &lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="CodeDesc"&gt; &lt;p&gt; Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur convallis metus et lectus venenatis rhoncus. Suspendisse potenti. Maecenas bibendum nisi ut velit luctus ultricies. Mauris at nibh a elit pretium varius. Nunc accumsan sagittis augue at facilisis. Phasellus et ante lorem, vitae laoreet enim. Donec vulputate, velit a lobortis eleifend, neque nibh rhoncus quam, non pharetra turpis mauris sed ligula. Ut rhoncus, felis ac scelerisque volutpat, turpis elit malesuada ante, vel varius lorem erat dapibus mi. Nullam nulla risus, aliquam sed tempus eu, dictum a est. &lt;/p&gt; &lt;/div&gt; &lt;p&gt;&lt;/p&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Apologies if I was not able to clearly describe my issue.</p> <p>Any help appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload