www.webdeveloper.com
Results 1 to 2 of 2

Thread: text box remove content

  1. #1
    Join Date
    Apr 2007
    Posts
    89

    text box remove content

    Hi all

    Can someone please tell me is there a way of removing unwanted text from a textbox during the submit process.

    I have a text box that asks for a domain name but i dont want the www. part just the rest of the domain. can javascript remove www. if its present.

    Thanks
    Aiden

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,672
    try this

    Code:
    function filter_value(){
    var txt = document.getElementById(your_posting_form_textaria_id).value;
    var unwanted = /www./i;
    document.getElementById(your_posting_from_textaria_id).value = txt.replace(unwanted, '');
    document.getElementById(your_posting_form_id).submit();
    }
    
    document.getElementById(your_posting_form_id).onsubmit = filter_value;
    example

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Filter value</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
    select{margin:5px 10px;padding:3px 7px 3px 5px;border:none;}
    div#content{text-align:center;padding-top:100px;}
    </style>
    <script type="text/javascript">
    function filter_value(){
    var txt = document.getElementById('inp').value;
    var unwanted = /www./ig;
    /*
    var unwanted = /(http:\/\/)?www./ig;
    use this if you want to remove http:// aswell
    */
    document.getElementById('inp').value = txt.replace(unwanted, '');
    /*
    the two lines below are just for testing
    remove them and uncomment the last line
    */
    document.getElementById('result').innerHTML = document.getElementById('inp').value;
    return false;
    //document.getElementById(your_posting_form_id).submit();
    }
    
    function set_posting_form(){
    document.getElementById('p_f').onsubmit = filter_value;
    }
    
    window.onload = set_posting_form;
    </script>
    </head>
    <body>
    <div id="content">
    <form id="p_f" action="">
    <textarea id="inp" cols="50" rows="5"></textarea><br /><br /><br />
    <input type="submit" />
    </form>
    <div id="result">&nbsp;</div>
    </div>
    </body>
    </html>
    Last edited by Padonak; 07-02-2010 at 01:16 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles