1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Trying to figure out how to do this

Discussion in 'Programming' started by chosenlight, Feb 11, 2009.

  1. #1
    I am trying to do the following, i hope someone will be able to help me out.

    I have one form with one input text field. I want to be able to take that input and break it off.

    For example : user inputs "word1 word2"

    I want to have that passed to the second page as "word1_word2". Any idea how i can do this? i dont need that info saved on my db, but i will if it simplifies things.

    Thanks a lot in advance, you guys never disappoint!
     
    chosenlight, Feb 11, 2009 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you want to change the value before the form is submitted (ie in the client browser) that means using javascript. Just use the replace() method to replace spaces with an underscore "_" character.

    http://www.w3schools.com/jsref/jsref_replace.asp

    BUT, javascript can be disabled. So it is usually better to do that kind of processing on the server with CF code. So .. is there any reason you cannot just pass "word1 word2" and do the string handling on the action page?
     
    cfStarlight, Feb 11, 2009 IP
  3. chosenlight

    chosenlight Active Member

    Messages:
    363
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Nope, i can do it on the action page, i just don't know how. They link you provided uses java; i know how to do it with java, but i didn't want to; just wanna use CF
     
    chosenlight, Feb 12, 2009 IP
  4. StefanV

    StefanV Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think it is best if you explain what you want tp do with the input. Is it always two words? Do you want to insert the words separately in the database or shall it be the complete phrase/set of words with some modification?

    If you want to split them, separate the words, the List functions is easiest.
    word_1 = listFirst(myInput,' ');
    word_2 = listLast(myInput,' ');

    or, of it is many words, maybe you want to create an array
    aWords = listToArray(myInput,' ');

    Note that the delimiter used is space (' ').

    But I think that before you can get a good answer, you need to give us a good question :)
     
    StefanV, Feb 12, 2009 IP
  5. chosenlight

    chosenlight Active Member

    Messages:
    363
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #5
    ok that helps a bit : Ill try to clarify my question. I have a search input box in a form. I want to pass that through to the action page as is. For example some one will input in that search box "what is the best dog breed". I want that to pass that through to my action page as "what is the best dog breed", but i also want a variable to equal "what+is+the+best+dog+breed" and "what_is_the_best_dog_breed" as well as "what is the best dog breed". I will use these two variables in the action action page, so as mentioned earlier, i do not need it saved on a db. However, i do not mind using a database and storing each word separate if it makes this task a whole lot easier.
    Thnx
     
    chosenlight, Feb 12, 2009 IP
  6. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It is javascript, not java. Big difference ;-)
     
    cfStarlight, Feb 13, 2009 IP
  7. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    While I don't understand what you are doing with these values, it seems like you want to replace a space character with something else. So have you looked at the replace() function in the documentation?
    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_02.html

    <cfset newValue1 = Replace(yourFormField, " ", "+", "all")>
    <cfset newValue2 = Replace(yourFormField, " ", "_", "all")>
     
    cfStarlight, Feb 13, 2009 IP
    chosenlight likes this.
  8. Jeff L

    Jeff L Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    where is a good place to buy a book or pdf to learn this.


    Thanks
     
    Jeff L, Feb 13, 2009 IP
  9. chosenlight

    chosenlight Active Member

    Messages:
    363
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #9
    cfstar....that helps a billion, thank you, ill give it a shot and and let you know how it works out.
     
    chosenlight, Feb 13, 2009 IP