Results 1 to 5 of 5

Thread: page into variables

  1. #1
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Question page into variables

    hi,
    i posted about this topic a few days ago! I found how to do most of it!
    but i did not get this part.
    i need a javascript code that can read the html code from the textarea and
    take all the elements and their attributes into variables.
    for example.
    there is an element text box name text1 with size and color attributes.
    so the script should make a variable called text1_size=<the size>
    and another text1_color=<the color>

    note: It should take all the variables of the element, as many as they are. and make variables like those in the above example.

    Thanks! in advance! Hope somebody has a solution!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I had to do something like that for this:

    http://home.comcast.net/~jscheuer1/side/dom_b.htm

    I forget how I did it though. You are welcome to look over the code for any insights:

    http://home.comcast.net/~jscheuer1/side/DOM_b_input.js

    If you have any questions, they may jog my memory. The code is annotated in two posts starting here:

    http://www.dynamicdrive.com/forums/s...sion#post52536
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default

    i only want it to directly read html code from textarea.
    and take. all the elements and their attributes into variables

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by midhul View Post
    i only want it to directly read html code from textarea.
    and take. all the elements and their attributes into variables
    There is no HTML code in textarea, only text. So, if I may take literally what you are saying, you don't need to read attributes. You need to parse the text. You know what I mean?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You want to do something like:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function parseAttys(el){
    var v = document.getElementById(el).value,
    m = v.match(/<[^ \/]+ [^\/]+>/g);
    for(var i = 0; i < m.length; ++i)
    m[i] = (i? '\n' : '') + m[i].match(/<([^ ]+)/)[1] + '_' + i + ' attributes:\n' + m[i].replace(/"/g, '').match(/ ([^ ]+=[^ >]+)/g).join('\n');
    return m.join('\n');
    }
    </script>
    </head>
    <body>
    <textarea id="ta" cols="50" rows="5"><span id="bob">Hey!</span><p align="center" width=100>Yo</p></textarea><br>
    <input type="button" value="Go" onclick="alert(parseAttys('ta'));">
    </body>
    </html>
    Right? I mean this isn't a solution, but it should be a step along the the way to one. What do you think?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •