Warning: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..../includes/class_bbcode.php on line 2083
HTML to JavaScript converter
Results 1 to 1 of 1

Thread: HTML to JavaScript converter

  1. #1
    Senior Member ghaza's Avatar
    Join Date
    Oct 2013
    Location
    Multan, Pakistan
    Posts
    354
    ΑΡ Credit
    3540

    HTML to JavaScript converter

    This clever utility converts normal HTML code to dynamically generated JavaScript instead. Very useful in applications where the code must be dynamically generated, such as contents inside a JavaScript scroller, text of a random quote script etc.

    Simply insert the below into the <BODY> section of your page:


    HTML Code:
    <script>
    
    // HTML to JavaScript converter
    // By John Krutsch (http://asp.xcentrixlc.com/john)
    // Moderator of the JavaScript Kit Help Forum: http://freewarejava.com/cgi-bin/Ultimate.cgi
    
    function scriptIt(val){
    val.value=val.value.replace(/"/gi,"&#34;")
    val.value=val.value.replace(/'/gi,"&#39;")
    valArr=escape(val.value).split("%0D%0A")
    val.value=""
    for (i=0; i<valArr.length; i++){
    val.value+= (i==0) ? "<script>\ninfo=" : ""
    val.value+= "\"" + unescape(valArr[i])
    val.value+= (i!=valArr.length-1) ? "\" + \n" : "\"\n" 
    }
    val.value+="\ndocument.write(info)\n<\/script>"
    }
    
    function ctrlA(el) {
    with(el){
    focus(); select() 
    }
    if(document.all){
    txt=el.createTextRange()
    txt.execCommand("Copy") 
    window.status='Selected and copied to clipboard!'
    }
    else window.status='Press ctrl-c to copy the text to the clipboard'
    setTimeout("window.status=''",3000)
    } 
    
    </script>
    <center>
    <form name="f">
    <input type="button" value="HTML -> JavaScript" onclick="scriptIt(document.f.t)" />
    <input type="reset" value="Reset">
    <input type="button" value="Select All" onclick="ctrlA(document.f.t)" />
    <br />
    <textarea name="t" cols="75"
    rows="20"></textarea>
    <br />
    </form>
    </center>

    Demo is available in the attachment..
    Attached Files Attached Files

Similar Threads

  1. Image Clock (JavaScript)
    By ghaza in forum Javascript and js libraries
    Replies: 0
    Last Post: 11-10-2013, 05:29 PM
  2. I need a code (html, javascript) for a list having ...
    By B.Ali in forum Website Templates
    Replies: 5
    Last Post: 11-08-2013, 04:11 PM
  3. HTML Tutorial - HTML Color Coding System - Color Names
    By web_guru in forum Web Designing
    Replies: 1
    Last Post: 03-14-2011, 06:18 AM
  4. HTML Tutorial - Beginning HTML Tags
    By web_guru in forum Web Designing
    Replies: 0
    Last Post: 07-08-2010, 04:28 PM
  5. javascript this keyword
    By AP admin in forum Javascript and js libraries
    Replies: 0
    Last Post: 07-03-2010, 06:17 PM

Posting Permissions

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