473,770 Members | 6,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex

I am trying to make this onClick work:
onClick="Format Str(('E',('F'(' G'('H')))))">

===============
var strTable = "\
<table border=1 width='100%'>\
<tr>\
<td width='50%'>@1</td>\
<td>@2</td>\
</tr>\
<tr>\
<td>@3</td>\
<td>@4</td>\
</tr>\
</table>"

function FormatStr(str) {
alert(arguments[0]+arguments[1]+arguments[2]+arguments[3]+arguments[4])
for ( i=1; i < arguments.lengt h; i++ )
str = str.replace(new RegExp("@"+i), arguments[i]);
return str;
}

function doIt() {
document.body.i nsertAdjacentHT ML("beforeEnd" , FormatStr(strTa ble, "A",
"B", "C", "D"));
}

<FORM >
<INPUT TYPE="button" value="Table" onClick="doIt() ">
<INPUT TYPE="button" value="FormatSt r" onClick="Format Str(('E',('F'('
G'('H')))))">
</FORM>
Jul 20 '05 #1
4 2425
Québec wrote:
I am trying to make this onClick work:
onClick="Format Str(('E',('F'(' G'('H')))))">
In Mozilla/5.0:
| Error: string is not a function
| Source File: javascript: alert(('E',('F' (' G'('H')))))
| Line: 1

In IE 6.0 SP-1 (translated):
| Line: 1
| Column: 1
| Error: Function expected
| Code: 0
| URL: [not of interest]

You are using the `(' operator without a keyword or an identifier
left-hand side or an expression inside. What did you want the above
argument(s) to display?
===============
var strTable = "\
<table border=1 width='100%'>\
<tr>\
<td width='50%'>@1</td>\
<td>@2</td>\
</tr>\
<tr>\
<td>@3</td>\
<td>@4</td>\
</tr>\
</table>"


Although supported in web browsers, you should not rely on `\' to continue
the string literal in the next line in all UAs as the JavaScript reference
specifies nothing of the kind. Use the concatenation operator `+' instead.
HTH

PointedEars
Jul 20 '05 #2
doIt prints a table with the letters A B C D in each cell.

onClick="Format Str('E', 'F',' G',('H'))))" is suppose to replace A B C D
with E F G H

Jul 20 '05 #3
Québec wrote:
doIt prints a table with the letters A B C D in each cell.

onClick="Format Str('E', 'F',' G',('H'))))" is suppose to replace
A B C D with E F G H


`(...)' outside of a string literal is nothing but a paranthesed
expression and thus here ('H') is the same as 'H'. And there are
more parantheses closed (4) than opened (2) here. I guess you are
looking for

onClick="Format Str('E', 'F',' G', '(\'H\')')"

Besides,

function FormatStr(str) {
alert(arguments[0]+arguments[1]+arguments[2]+arguments[3]+arguments[4])
for ( i=1; i < arguments.lengt h; i++ )
str = str.replace(new RegExp("@"+i), arguments[i]);
return str;
}

will not work as supposed since "E" is assigned to `str' (as it is
the first argument or ...arguments[0]) and there is no `@x' in it to
replace.

function FormatStr() {
// i as local variable and arguments is zero-based
for (var i = 0; i < arguments.lengt h; i++)
strTable =
strTable.replac e(new RegExp("@" + (i + 1)), arguments[i]);
return strTable;
}

will do the trick one time. If you need `strTable' unchanged, assign
its value to a local variable and refer to that variable for replace.

See
http://devedge.netscape.com/library/...s.html#1008302
and
http://devedge.netscape.com/library/...n.html#1193137
for details.
HTH

PointedEars
Jul 20 '05 #4
I think, I have not been specific enough. The idea is to change the letters
in the already made table with the second function.
----------------
var strTable = "";
strTable += "<table border=1 width='100%'>"
strTable += "<tr>"
strTable += "<td width='50%'>@1</td>"
strTable += "<td>@2</td>"
strTable += "</tr>"
strTable += "<tr>"
strTable += "<td>@3</td>"
strTable += "<td>@4</td>"
strTable += "</tr>"
strTable += "</table>"

function FormatStr(str) {
for ( i=1; i < arguments.lengt h; i++ )
str = str.replace(new RegExp("@"+i), arguments[i]);
return str;
}

function doIt() {
document.body.i nsertAdjacentHT ML("beforeEnd" , FormatStr(strTa ble, "A",
"B", "C", "D"));
}
//--</script

Substitutes @1 with arg1, @2 with arg2 and so on at the passed
string.

<p><FORM >
<INPUT TYPE="button" value="doIt" onClick="doIt() ">
<INPUT TYPE="button" value="FormatSt r2" onClick="Format Str2('E', 'F',' G',
'H')">
</FORM>
Jul 20 '05 #5

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

Similar topics

9
4592
by: Tim Conner | last post by:
Is there a way to write a faster function ? public static bool IsNumber( char Value ) { if (Regex.IsMatch( Value.ToString(), @"^+$" )) { return true; } else return false; }
6
2503
by: Extremest | last post by:
I have a huge regex setup going on. If I don't do each one by itself instead of all in one it won't work for. Also would like to know if there is a faster way tried to use string.replace with all the right parts in there in one big line and for some reason that did not work either. Here is my regex's. static Regex rar = new Regex("\\.part.*", RegexOptions.IgnoreCase); static Regex par = new Regex("\\.vol.*", RegexOptions.IgnoreCase);
7
2588
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward slash then some numbers. For some reason I am not getting that. It won't work at all in 2.0
3
2702
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def RN(name, regex): """protect using () and give an optional name to a regex""" if name:
15
50260
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
0
9591
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
9425
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
10053
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
10001
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
9867
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...
0
8880
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...
1
7415
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...
1
3969
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
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.