SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    RS, Brazil
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing textarea content

    Hello guys!

    I'm creating a simple editor for a customer Its basically many fields that will populate dinamically a textarea. The insertion is Ok. the problem is when the user enters in "edit mode" to change something in the inserted content.

    I need to parse the textarea content and then split it into the other form fields

    for example... my textarea contains:

    Code:
    <!-- model -->1<!-- /model -->
    <!-- header -->img de cabecalho<!-- /header -->
    <!-- content --> something here... <!-- /content -->
    <!-- link1 -->link 1<!-- /link1 -->
    Each <!-- XXX --> corresponds to something that must be extracted from this textarea

    my questions question are:
    1 - how to read the content of a textarea and manipulate it's data? (to remove the metadate and pre-loaded values
    2 - how to get everything between <!-- link1 --> and <!-- /link1 -->

    thanks in advice.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This is normally something done in a serverside language (parsing and replacement) such as PHP. Any reason you're doing this in Javascript?

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    RS, Brazil
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes. It's a plugin to be installed with a WYSIWYG editor...

    I've found this solution. It may not be the best. but it works.

    Code:
    	function parseMe() {
    		content = document.getElementById("introtext").value;
    		
    		try {
    			model = content.substring(content.indexOf("<!-- model -->")+14,content.indexOf("<!-- /model -->")+15);
    			content = content.replace(content.substring(content.indexOf("<!-- model -->"),content.indexOf("<!-- /model -->")),"");
    		} catch (er) {
    			alert('ocorreu um erro ao capturar os dados do template');
    			return false;
    		}
    		document.getElementById("introtext").value = content;
    	}


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •