Results 1 to 3 of 3

Thread: Change text dynamically when certain text is entered in form field?

  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Change text dynamically when certain text is entered in form field?

    Hi

    I want test on webpage to change when something is written in a text field. It will also trigger different text on the webpage when it detects certain words in the text field.

    For example:

    When nothing is written in the text field it will say "Nothing is written". When anything is written it will say "Something is written". When the script detects certain words in the form field it i.e. "keyword" it will say "Keyword is written".

    Anyone knows how to do this?

    Also will it use alot of CPU or anything on the users PC?

    Thanks in advance

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP is a serverside language and that means that everything is processed on the server when the page is loaded. It will be pure html (only), except that this html will be different depending on what was entered.
    Javascript operates on the user's computer and could accomplish something similar: disadvantages: this does use the visitor's CPU (but in this case it wouldn't be too bad except on really slow systems) and most importantly it requires that the user has javascript available. If not, they just don't see anything. (With PHP, there is no requirement of the user at all-- the server deals with all processing then outputs the right html). Advantage: this operates on the user's computer while the page is loaded, so you don't need to refresh the page to get updates-- with PHP you need to reload the page every time (by submitting the form).

    I'd recommend PHP unless you plan to have the user submit many words in sequence (and maybe even then).

    This is very "easy" to do in PHP, but it does mean that you need to understand the language. This is exactly the sort of thing PHP is designed for, so in that sense it's easier than Javascript (though it wouldn't be especially hard in JS either).

    If you do plan to use PHP, just start with some tutorials (any tutorials for the very basics then a tutorial about handling forms-- there will be lots).

    -Look into html forms/naming (an element called name="MYNAME" will be available based on that name in the PHP after the form is submitted).
    -Learn how to use either $_GET or $_POST (based on method="post"/"get"). In most cases, POST will be the smoothest, though GET would work also.
    -Use some basic if statements to determine the output-- check if there is data, if not show one message, if so, parse it, etc...
    -The only (somewhat) advanced part of what you're doing is checking for keywords. You can probably just use if (strpos($TEXT,$keyword)!==FALSE) {......, but that will mean writing one line for each. If you have many keywords, you'll want to create an array (list) of them and loop through it. And if you want to actually parse some sort of linguistic meaning (even at a basic level), that'll be harder. But it doesn't sound like you need that.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the answer

    I will look into this

Bookmarks

Posting Permissions

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