Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-08-2012, 04:55 PM   PM User | #1
alphamale
New Coder

 
Join Date: Oct 2012
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
alphamale is an unknown quantity at this point
Unhappy Deleting string from input field

I have an input field that ends up having a lot of automated <pre></pre> tags.

Can I delete all of these from the input fields content on page load? and then can i wrap the fields contents in these tags on form submission?

basically so the user never has to see them.

Thanks,
Michael

Last edited by alphamale; 10-08-2012 at 06:34 PM..
alphamale is offline   Reply With Quote
Old 10-08-2012, 05:18 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
RegEx replace. UNTESTED.

string.replace(/\<(\/)*pre\>/g,"") when the page loads (or can be done server-side.. probably easier)

On form submit, again, server-side would be best, but you can use JavaScript to add the tags around the value.

inputID.value = "<pre>" + inputID.value + "</pre>"
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Users who have thanked WolfShade for this post:
alphamale (10-08-2012)
Old 10-08-2012, 05:34 PM   PM User | #3
alphamale
New Coder

 
Join Date: Oct 2012
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
alphamale is an unknown quantity at this point
Quote:
Originally Posted by WolfShade View Post
RegEx replace. UNTESTED.

string.replace(/\<(\/)*pre\>/g,"") when the page loads (or can be done server-side.. probably easier)

On form submit, again, server-side would be best, but you can use JavaScript to add the tags around the value.

inputID.value = "<pre>" + inputID.value + "</pre>"
string.replace(/\<(\/)*pre\>/g,"")

I dont get this, what are all the special characters for? Does it just remove all <pre> and </pre> tags?

and for: inputID.value = "<pre>" + inputID.value + "</pre>"

could I use $newText = "<pre>"".$oldText."</pre>";
?

Thanks!
alphamale is offline   Reply With Quote
Old 10-08-2012, 05:35 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
mmm... but will the user be able to edit the input fields once the page has loaded, and are there more than once set of tags per input field?
xelawho is offline   Reply With Quote
Old 10-08-2012, 05:45 PM   PM User | #5
alphamale
New Coder

 
Join Date: Oct 2012
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
alphamale is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
mmm... but will the user be able to edit the input fields once the page has loaded, and are there more than once set of tags per input field?
Heres an example of how bad the auto-tagging is getting...

Code:
<pre><pre><pre><pre><pre><pre><pre><pre>Testing description field</pre></pre></pre></pre></pre></pre></pre></pre>
This is a field for the user to edit (a profile update form).

I need to remove all <pre> and </pre> tags from that field on page load. Then rewrap the submission in <pre></pre> I know how to rewrap but not how to remove :/

Thanks
alphamale is offline   Reply With Quote
Old 10-08-2012, 05:46 PM   PM User | #6
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Quote:
Originally Posted by alphamale View Post
string.replace(/\<(\/)*pre\>/g,"")

I dont get this, what are all the special characters for? Does it just remove all <pre> and </pre> tags?

and for: inputID.value = "<pre>" + inputID.value + "</pre>"

could I use $newText = "<pre>"".$oldText."</pre>";
?

Thanks!
I haven't tested it (not enough time, at work), but the extra characters (I assume you mean the backslashes) are for escaping, making the <, /, and > characters "literals" instead of programming commands.

It _should_ just remove the "<pre>" and "</pre>" tags from the string.

As far as $newText and whatnot, that looks like PHP, not JavaScript.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 10-08-2012, 05:55 PM   PM User | #7
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
here's how WolfShade's regex would work on page load:

Code:
<body>
<input id="txt" value="<pre><pre><pre><pre><pre><pre><pre><pre>Testing description field</pre></pre></pre></pre></pre></pre></pre></pre>"/>
<script type="text/javascript">
document.getElementById("txt").value=document.getElementById("txt").value.replace(/\<(\/)*pre\>/g,"")
</script>
</body>
if you have the rewrap bit sorted, you should be fine.
xelawho is offline   Reply With Quote
Old 10-08-2012, 06:07 PM   PM User | #8
alphamale
New Coder

 
Join Date: Oct 2012
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
alphamale is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
here's how WolfShade's regex would work on page load:

Code:
<body>
<input id="txt" value="<pre><pre><pre><pre><pre><pre><pre><pre>Testing description field</pre></pre></pre></pre></pre></pre></pre></pre>"/>
<script type="text/javascript">
document.getElementById("txt").value=document.getElementById("txt").value.replace(/\<(\/)*pre\>/g,"")
</script>
</body>
if you have the rewrap bit sorted, you should be fine.
Okay thanks again.

Just to confirm that this would be okay?

Code:
<body>
<textarea id="description"> <?php $value['description'] ?> </textarea>
<script type="text/javascript">
document.getElementById("description").value=document.getElementById("description").value.replace(/\<(\/)*pre\>/g,"")
</script>
</body>
alphamale is offline   Reply With Quote
Old 10-08-2012, 06:11 PM   PM User | #9
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
That should do it. I can never remember if * or ? is "zero or more of the preceeding character", but it's one or the other.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 10-08-2012, 06:35 PM   PM User | #10
alphamale
New Coder

 
Join Date: Oct 2012
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
alphamale is an unknown quantity at this point
Worked like a charm! Thanks
alphamale is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:47 AM.


Advertisement
Log in to turn off these ads.