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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Help with Script that filters paragraph. If 1 word exists, write a warning

    I'm looking to write a script that does the following:

    1) It reviews a paragraph that is dynamically created via a tmp_Remarks tag.

    2) If the phrase "short sale" or "shortsale" is present, Perform 2 actions:
    A) Put a Red Asterik at the top of the page
    B) at the bottom, repeat the asterik and a sentence describing what a "short sale " is.

    So in other words, there are 100 HTML pages.
    Each one has a unique paragraph describing a house

    Most will be like this:

    "This is a fabulous place, you should buy it..."

    But on the rare occasion that it has "Short Sale" in it like

    "This property is a short sale, please make an offer"

    It would trigger the script and put an astrik on the top of the page and separately a description of what a "short sale" is at the bottom of the page.

    Is this possible?
    Thanks!
    JP

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    Hi, if each of your tags have a id attribute assigned to them this should work,

    Code:
    <script>
    function check_tag(id)
    {
    
    var tag = document.geElementById(id).innerHTML;
    var tag_lower = tag.toLowerCase();
    
    if(tag_lower.indexof("shortsale") == -1 && tag_lower.indexof("short sale") == -1)
    {
    
    //the text was not found in the document. Put all processing in here.
    
    }
    else
    {
    
    //the text as been found and the processing to inticate this should be placed here
    
    }
    
    }
    </script>
    I hope this helps you, but you will need to write the code for what you want it to do when it does/doesn't find the text within the if statements.

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Awesome.
    Sorry for the ignorance, but which is the variable that would turn into a paragraph?

    I tried changing "id" to "This is a lovely home, come buy it" but that didn't work for me.

    Also did I correctly write the IF then statement?


    <script>
    function check_tag(id)
    {

    var tag = document.geElementById(id).innerHTML;
    var tag_lower = tag.toLowerCase();

    if(tag_lower.indexof("shortsale") == -1 && tag_lower.indexof("short sale") == -1)
    {

    //the text was not found in the document. Put all processing in here.
    document.write( "This is short sale, the bank will have to approved..." );
    }
    else
    {

    //the text as been found and the processing to inticate this should be placed here
    document.write( "This is not short sale." );
    }

    }
    </script>

    Thanks!
    JP

  • #4
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    Code:
    <script>
    
    function init()
    {
    
    check_tag('check1');
    
    }
    
    window.onload = init;
    
    </script>
    
    <div id="check1">This is a shortsale</div>
    You will have to add a function call for every paragraph you want to check, the id is the id attribute that is assigned to the tag which you want to check.

  • #5
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    So I put it all together, and if I paste this code in, it should trigger the DocWrite right?

    <script>

    function init()
    {

    check_tag('check1');

    }

    window.onload = init;

    </script>


    <script>
    function check_tag(id)
    {

    var tag = document.geElementById(id).innerHTML;
    var tag_lower = tag.toLowerCase();

    if(tag_lower.indexof("shortsale") == -1 && tag_lower.indexof("short sale") == -1)
    {

    //the text was not found in the document. Put all processing in here.
    document.write( "Test This is short sale, the bank will have to approve..." );
    }
    else
    {

    //the text as been found and the processing to inticate this should be placed here
    document.write( "This is not short sale." );
    }

    }
    </script>

    <div id="check1">This is a shortsale</div>
    </body>
    </html>

    The page should then say:

    This is a shortsale
    Test This is short sale, the bank will have to approve...

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Why not try it? That way you could learn something.

  • Users who have thanked Philip M for this post:

    jpater74 (01-05-2008)

  • #7
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Philip,
    I did try it. I spend 2 hours trying it.
    I must be doing something wrong.
    Frank

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    function check_tag(id) {
    var tag = document.getElementById(id).innerHTML;


    Javascript is case sensitive:-

    if (tag_lower.indexOf("shortsale") == -1 && tag_lower.indexOf("short sale") == -1)

    I think you will find that it works after those corrections have been made.

    To recap:-

    ============================================
    <script type = "text/javascript">

    window.onload = init; // be careful not to have two onload events in your page

    function init() {
    check_tag("check1");
    }

    function check_tag(id) {

    var tag = document.getElementById(id).innerHTML;
    var tag_lower = tag.toLowerCase();

    if ((tag_lower.indexOf("shortsale") == -1) && (tag_lower.indexOf("short sale") == -1)) {
    //the text was not found in the document. Put all processing in here.
    document.write( "Test This is short sale, the bank will have to approve..." );
    }

    else {
    //the text as been found and the processing to indicate this should be placed here
    document.write( "This is not a short sale." );
    }
    }
    </script>

    <div id="check1">This is a shortsale</div>

    =======================================================


    But is not the logic reversed?
    //the text was not found in the document. Put all processing in here.
    document.write( "Test This is short sale, the bank will have to approve..." );

    Remember that document.write erases the current page and creates a new one. In other words it cannot be used to update the content of your page after that page has been loaded.
    Last edited by Philip M; 12-22-2007 at 07:12 PM.

  • Users who have thanked Philip M for this post:

    jpater74 (01-05-2008)


  •  

    Posting Permissions

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