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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    682
    Thanks
    24
    Thanked 1 Time in 1 Post

    Checking for existence of certain text?

    I'm using this onclick event below:

    Code:
    onClick="javascript:modify('text value here');" href="#" onFocus="if(this.blur)this.blur()">Click Here</a>
    I use this to load whatever text value there is into a text box area, but was wondering if there was a way I could check for the existence of a certain piece of text & if found it would load some different pre-specified text instead into the text box field?

    Thanks!

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please try the following example

    PHP Code:
    <script type="text/javascript">
    <!--
    function 
    modify(str){
    if(
    str.indexOf("text value here")!=-1){
    document.forms["myForm"]["t1"].value="New String"
    }
    else{
    document.forms["myForm"]["t1"].value=str
    }

    }
    //-->
    </script>


    <a href="#null" onclick="modify('text value here')">Click Here</a>
    <a href="#null" onclick="modify('Hello World')">And Here</a>

    <form name="myForm">
    <input type="text" name="t1">
    </form> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.


  •  

    Posting Permissions

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