Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • Users who have thanked WolfShade for this post:

    alphamale (10-08-2012)

  • #3
    New Coder
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,775
    Thanks
    55
    Thanked 519 Times in 516 Posts
    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?

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,775
    Thanks
    55
    Thanked 519 Times in 516 Posts
    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.

  • #8
    New Coder
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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>

  • #9
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #10
    New Coder
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Worked like a charm! Thanks


  •  

    Posting Permissions

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