Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Need help with JavaScript Replace Method for multiple textboxes

Reply
Thread Tools

Need help with JavaScript Replace Method for multiple textboxes

 
 
Barnes
Guest
Posts: n/a
 
      07-03-2004
Hi,

Can anyone please tell me how I can use the replace method to replace
a character if it occures in more than one textbox without having to
write separate function for each textbox.

The code below is the basic way to use the replace method but it only
allows for one textbox.

I'm sure I need a loop in there but I'm not sure how to use that
without affecting the replace method.

Any help would be greatly appreciated!

---------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<script language="javascript">

function stringReplace(form) {
var replaceStr = form.textfield1.value
var pattern = /\'/g;
form.textfield1.value = replaceStr.replace(pattern, "''");
}
</script>

</head>

<body>

<form name="form1" method="post" action="JStest_redirect.asp">
<p>fname:
<input type="text" name="textfield1" size="20">
</p>
<p>lname:
<input type="text" name="textfield2" size="20">
</p>
<p>
<input onclick="return stringReplace(form)" type="submit"
name="Submit" value="Submit">
</p>

</form>
</body>
</html>
 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      07-03-2004
Barnes wrote:
> Hi,
>
> Can anyone please tell me how I can use the replace method to replace
> a character if it occures in more than one textbox without having to
> write separate function for each textbox.
>
> The code below is the basic way to use the replace method but it only
> allows for one textbox.
>
> I'm sure I need a loop in there but I'm not sure how to use that
> without affecting the replace method.
>
> Any help would be greatly appreciated!
>
> ---------------------------------------------
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
>
> <script language="javascript">
>
> function stringReplace(form) {
> var replaceStr = form.textfield1.value
> var pattern = /\'/g;
> form.textfield1.value = replaceStr.replace(pattern, "''");
> }
> </script>
>

function stringReplace(form,identifier) {
f=form.length
while(f--){
if(form[f].type=="text" && form[f].name.indexOf(identifier)!=-1){
form[f].value = form[f].value.replace(/\'/g;, "''");
}
}
}
<input onclick="stringReplace(this.form,'textfield')" type="submit"
name="Submit" value="Submit">

Mick

> </head>
>
> <body>
>
> <form name="form1" method="post" action="JStest_redirect.asp">
> <p>fname:
> <input type="text" name="textfield1" size="20">
> </p>
> <p>lname:
> <input type="text" name="textfield2" size="20">
> </p>
> <p>
> <input onclick="return stringReplace(form)" type="submit"
> name="Submit" value="Submit">
> </p>
>
> </form>
> </body>
> </html>

 
Reply With Quote
 
 
 
 
Barnes
Guest
Posts: n/a
 
      07-08-2004
Mick White <(E-Mail Removed)> wrote in message news:<renFc.3035$(E-Mail Removed)>...
> Barnes wrote:
> > Hi,
> >
> > Can anyone please tell me how I can use the replace method to replace
> > a character if it occures in more than one textbox without having to
> > write separate function for each textbox.
> >
> > The code below is the basic way to use the replace method but it only
> > allows for one textbox.
> >
> > I'm sure I need a loop in there but I'm not sure how to use that
> > without affecting the replace method.
> >
> > Any help would be greatly appreciated!
> >
> > ---------------------------------------------
> > <html>
> > <head>
> > <title>Untitled Document</title>
> > <meta http-equiv="Content-Type" content="text/html;
> > charset=iso-8859-1">
> >
> > <script language="javascript">
> >
> > function stringReplace(form) {
> > var replaceStr = form.textfield1.value
> > var pattern = /\'/g;
> > form.textfield1.value = replaceStr.replace(pattern, "''");
> > }
> > </script>
> >

> function stringReplace(form,identifier) {
> f=form.length
> while(f--){
> if(form[f].type=="text" && form[f].name.indexOf(identifier)!=-1){
> form[f].value = form[f].value.replace(/\'/g;, "''");
> }
> }
> }
> <input onclick="stringReplace(this.form,'textfield')" type="submit"
> name="Submit" value="Submit">
>
> Mick
>
> > </head>
> >
> > <body>
> >
> > <form name="form1" method="post" action="JStest_redirect.asp">
> > <p>fname:
> > <input type="text" name="textfield1" size="20">
> > </p>
> > <p>lname:
> > <input type="text" name="textfield2" size="20">
> > </p>
> > <p>
> > <input onclick="return stringReplace(form)" type="submit"
> > name="Submit" value="Submit">
> > </p>
> >
> > </form>
> > </body>
> > </html>



Mick,
Thanks for your quick reply.

I used your suggestion and developed a for loop but the apostrophes
are not getting replace when the form is submitted. Can you please
take a look at the for loop code and see if you can find anything
wrong. Thank you!!

-------------

<script Language = "JavaScript" Type="text/javascript">

function stringReplace(form)
{
var replaceStr = form.value
var patter = /\'/g;
form.value = replaceStr.replace(pattern, "'");
var elem = form.elements[i];

for (i = 0; i < form.length; i++)
}

if(form.type == "text")
{
stringReplace(elem);
}
}
}

</script>

....html...<form method="POST" action="ER_AddPost.asp" name="form1"
onsubmit="stringReplace(this.form)">
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [Pyrex] pyrex functions to replace a method (Re: replace a method Greg Ewing Python 2 06-29-2006 05:25 PM
pyrex functions to replace a method (Re: replace a method in class:how?) Brian Blais Python 1 06-27-2006 12:13 PM
Populating multiple textboxes with multiple records for update page Drew ASP General 7 11-10-2004 02:21 PM
Please help!!! Need datagrid selection to fill textboxes...Need quick!! TN Bella ASP .Net 1 06-18-2004 01:31 AM
Need help...with multiple textboxes and SQL....please help! Teep ASP .Net 1 06-17-2004 06:26 AM



Advertisments