need help in defining function
I am writing code for my form which has 2 textbox One is labelled as "search" and the other one is "replace" and one textarea. If a user enters "hello how are you" in the textarea and user needs to change that hello to hi, he/she needs to enter "hello" in search textbox and "hi" in "replace" textbox. There is another button that says "replace now", if user clicks that button hello changes to hi.
Can anyone give me some hints please. I am so confused how can I define such function?
string.replace();. basically you would create a custom function that will combine what the user typed in the search box and in the replace box and pass them as arguments to replace method. finally, the result is set back to the textbox that contain the text.
Now I got the concept.
However, I dont want my text in textarea to be hardcoded. User can enter any sentence and they should be able to change their words in textarea using search and replace.
Do I do that like this?
var str = replaceform.txt.value; //replaceform is the name of the form; txt is the textarea's id
document.write(str.replace(/how can I get search's text area value?/, "how can I get ")replace's text area value?);
what goes inside str.replace()??????? How can I get the user entered text area's value from search and replace textarea??
basically you will have at least 3 fields: textarea that contain the user's text (txt), input text for string to search (sech), and input text for text to replace with (repl). and the function would be something like follow:
txt.value = txt.value.replace(sech.value, repl.value);
assuming that txt, sech and repl are reference to each respective element. the value property refer to the containing text of each field.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)