bravo14 Posted January 9, 2015 Share Posted January 9, 2015 I am trying to populate a textarea with the text up to the first <br> tag in a html editor using the code below. <script> function setIntro_en() { var title = document.getElementById('mtxStory_en').html(); alert (title); var title = title.split('<br>')[0]; alert(title); <!--document.getElementById('mtxIntro_en').value = title; --> } </script> I am getting an error saying 'document.getElementById(...).html is not a function' Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/ Share on other sites More sharing options...
requinix Posted January 9, 2015 Share Posted January 9, 2015 That'd be because it does not exist. There is no function "html" on DOM elements. Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502238 Share on other sites More sharing options...
bravo14 Posted January 9, 2015 Author Share Posted January 9, 2015 Changed it to jQuery using the following <script type="text/javascript"> $(document).ready( function() { $('#mtxStory_en').blur(function(){ var what = $(this).html(); alert (what); $('#mtxIntro_en').html(what); }); }); </script> but the textarea with the id mtxIntro_en doesn't populate and I don't get any errors displayed in firebug. Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502257 Share on other sites More sharing options...
requinix Posted January 9, 2015 Share Posted January 9, 2015 What's the HTML? Particularly to do with the textareas. Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502259 Share on other sites More sharing options...
bravo14 Posted January 9, 2015 Author Share Posted January 9, 2015 <script type="text/javascript"> $(document).ready( function() { $('#mtxStory_en').blur(function(){ var intro = $("#mtxStory_en").html().split("<br>")[0]; alert (intro); $('#mtxIntro_en').html(intro); }); }); </script> the html for the textareas <table> <tr> <td width="150" class="label">Headline</td> <td class="content"> <input name="txtHeadline_en" onBlur="setIdentifier_en();" type="text" class="box" id="txtHeadline_en" size="50" maxlength="100"></td> </tr> <tr> <td width="150" class="label">Story</td> <td class="content"> <textarea name="mtxStory_en" cols="200" rows="90" class="editor" id="mtxStory_en"></textarea></td> </tr> <tr> <td width="150" class="label">Identifier</td> <td class="content"><input name="txtIdentifier_en" type="text" id="txtIdentifier_en" class="box"> </td> </tr> <tr> <td width="150" class="label">Introduction</td> <td class="content"><textarea name="mtxIntro_en" cols="70" rows="4" class="box" id="mtxIntro_en"></textarea></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502260 Share on other sites More sharing options...
CroNiX Posted January 9, 2015 Share Posted January 9, 2015 Those are form elements, you want to get and set their val(), not their html(). 1 Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502306 Share on other sites More sharing options...
bravo14 Posted January 9, 2015 Author Share Posted January 9, 2015 (edited) Is that even if the textarea contains html from a html editor? Edited January 9, 2015 by bravo14 Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502316 Share on other sites More sharing options...
CroNiX Posted January 9, 2015 Share Posted January 9, 2015 Yes, it's whatever the VALUE of the form control is, regardless of the content type. As far as a form is concerned, it's all just text. Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502317 Share on other sites More sharing options...
bravo14 Posted January 9, 2015 Author Share Posted January 9, 2015 Unfortunately that still hasn't worked, would it have anything to do with the fact that the html editor gets put inside an iframe? Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502335 Share on other sites More sharing options...
CroNiX Posted January 9, 2015 Share Posted January 9, 2015 It very well could. Not sure...I never use iFrames. Too much of a bother. Is the iFrame content coming from your site (same site), or a remote site? If it's a remote site, it's subject to the Same Origin Policy. http://en.wikipedia.org/wiki/Same-origin_policy Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502339 Share on other sites More sharing options...
bravo14 Posted January 9, 2015 Author Share Posted January 9, 2015 (edited) The I frame gets generated by the html editor (elrte) Edited January 9, 2015 by bravo14 Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502342 Share on other sites More sharing options...
CroNiX Posted January 9, 2015 Share Posted January 9, 2015 You should google for "jquery selector iframe". Basically you'll have to give your iframe an ID (it may already have it), and use that to access the contents() of the iframe, and then you can grab whatever elements are in the body of the iframe. Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502344 Share on other sites More sharing options...
CroNiX Posted January 9, 2015 Share Posted January 9, 2015 It's not as straightforward or simple as normal, because an iFrame can be compared to a "different web page" and not a part of the main page you are viewing. It's almost like having 2 tabs open in the browser. There are extra steps needed to access the iframed content. Quote Link to comment https://forums.phpfreaks.com/topic/293771-documentgetelementbyidhtml-is-not-a-function/#findComment-1502345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.