Jump to content

document.getElementById(...).html is not a function


bravo14
 Share

Recommended Posts

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'

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

<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>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.