/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@PadonakJul 02.2010 — 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;[/CODE]


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>[/CODE]
×

Success!

Help @aiden857181 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...