473,698 Members | 2,198 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 1468
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
19569
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
3676
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
3482
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
5194
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
2105
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
50247
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
9282
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
3663
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
5090
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
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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
9029
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...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6524
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
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...
1
3051
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
2332
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.