473,732 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string().replac e() usage...


Folks,

Can someone help my syntax?

var z=myForm.myInpu tTag.value.stri ng().replace(" ","-");

I would expect the above to allow z to take the value of an input tag
(called myInputTag) and replace spaces with dashes...

It doesn't change the string - nor do I get errors in the Mozilla
javascript conole...

All help, via the newsgroup (for all to learn) is appreciated, thanks
randelld
Jul 23 '05 #1
4 1474
All form values are already interpretted as "string" data types.
Remove the ".string()" from your statement, and it should work. Note
that this change will only put the updated string into your variable,
not the form, as you currently have the code written.

Make the update, then do an "alert()" on the variable to make sure
everything is cool.

Jul 23 '05 #2
Randell D. wrote:
Folks,

Can someone help my syntax?

var z=myForm.myInpu tTag.value.stri ng().replace(" ","-");

I would expect the above to allow z to take the value of an input tag (called myInputTag) and replace spaces with dashes...

It doesn't change the string - nor do I get errors in the Mozilla
javascript conole...

All help, via the newsgroup (for all to learn) is appreciated, thanks
randelld


You may be thinking of the Object.toString () method; no such thing as a
..string() method. Also: is 'myForm' simply the name of the form? If so
you'll need to use either document.myForm , or
document.getEle mentById('myFor m') with <form id="myForm"...> .
String.replace works with two string arguments, but it's far more
versatile with a regular expression and a replacement string (or
callback function):

var z = document.myForm .myInputTag.val ue.replace(/ /g, '-');

If you wanted *one* dash, even for multiple spaces:

var z = document.myForm .myInputTag.val ue.replace(/ +/g, '-');

Jul 23 '05 #3
RobB wrote:
Randell D. wrote:
Folks,

Can someone help my syntax?

var z=myForm.myInpu tTag.value.stri ng().replace(" ","-");

I would expect the above to allow z to take the value of an input tag


(called myInputTag) and replace spaces with dashes...

It doesn't change the string - nor do I get errors in the Mozilla
javascript conole...

All help, via the newsgroup (for all to learn) is appreciated, thanks
randelld

You may be thinking of the Object.toString () method; no such thing as a
.string() method. Also: is 'myForm' simply the name of the form? If so
you'll need to use either document.myForm , or
document.getEle mentById('myFor m') with <form id="myForm"...> .
String.replace works with two string arguments, but it's far more
versatile with a regular expression and a replacement string (or
callback function):

var z = document.myForm .myInputTag.val ue.replace(/ /g, '-');

If you wanted *one* dash, even for multiple spaces:

var z = document.myForm .myInputTag.val ue.replace(/ +/g, '-');

Thanks for that - I had used a regexp as I didn't believe it was
required... now it works...

Cheers
Randell D.
Jul 23 '05 #4
Spats30 wrote:
All form values are already interpretted as "string" data types.
Remove the ".string()" from your statement, and it should work. Note
that this change will only put the updated string into your variable,
not the form, as you currently have the code written.

Make the update, then do an "alert()" on the variable to make sure
everything is cool.


Yeah, I had tried sending the output via alert() and even tried with and
without string. I don't know why but when I replaced my arguements in
replace() with a regular expression (suggested in a follow on post from
yours) it worked...

Thanks though,
Randell D.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
19574
by: Niels Bosboom | last post by:
Hi! I am using PHP4.3.3 on a windows XP platform. I am building a small program that will allow my students to subscribe and unsubscribe from a service that will let them know when new results of their exams are added to the webpage of school. Since I am not allowed to use mySQL as a database, I am using a simple flat text-file to store the emailadresses submitted by my students. I can already add addresses to the file, even after I...
4
3678
by: beliavsky | last post by:
The code for text in open("file.txt","r"): print text.replace("foo","bar") replaces 'foo' with 'bar' in a file, but how do I avoid changing text inside single or double quotes? For making changes to Python code, I would also like to avoid changing text in comments, either the '#' or '""" ... """' kind.
4
3489
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if substrings need be replaced, or one character needs be changed, what shall I do? Is it better to convert strings to UCS-32 before manipulation? But on Windows, wchar_t is 16 bits which isn't enough for characters which can't be simply encoded...
6
5195
by: rithesh.rg | last post by:
Hello, Given below is a part of my code. In the code i am trying to parse through a string and replace all "+" characters by "*". string enc_msg = Convert.ToBase64String(full_enc); for (i = 0; i < enc_msg.Length; i++) {
1
2110
by: shapper | last post by:
Hello, I have a XLST file where I have the phrase "HERE". Something like: <xsl:text>HERE</xsl:text> I want to replace "HERE" by "UPDATED" and save the file.
15
50255
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
5
9294
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of strings. Then, I googled and found this suggestion of some JavaScript Tutorials, so I used replace with a regex with a global switch:
16
3669
by: yu_kuo | last post by:
Is there any comparison data on perfomance difference between std::string and c style string? Or maybe if there are source code which could be used to measuer on different compiler/platform, in a systematic way?
3
5091
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages (Java). It stores character strings, and resizes itself to accommodate new strings when needed. Interface: ----------
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.