473,513 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hyphen in variable causing unwanted subtraction!

Max
I'm reading some files in a directory using php code for the end result of
allowing these files to be deleted.

The problem is some of the file names have hyphens in them, and this cannot
be changed.

The php code prints each file name on a page and has a delete link for each
seperate file. I pass the name of the file via a variable using onclick to a
javascript confirm function when the delete link is clicked on. But when the
javascript confirm dialog box appears and asks 'Are you sure you want to
delete file xxxx', if the file name was for example 120-01, the javascript
dialog would display will display 119 instead.

How can I get around this? I started to read something about using brackets,
but I can't seem to get it working.

Here is the relevant code:

Let's say $id[0] = "120-01";

print " <td style=\"background-color:silver\" width=\"5%\"
align=\"center\"><b><a href=\"javascript:confirm_entry($id[0],$dir_count
\">Delete</a></b></td>";
<script language=\"JavaScript\">

function confirm_entry(id,dir_count) {
input_box=confirm(\"Are you sure you want to delete MTR ID \"+id+\" ?\");
if (input_box==true) {

window.location = \"$self?delete=\"+id+\"?dircount=\"+dir_count

}
}
</script>
The confirm will end up as "Are you sure you want to delete MTR ID 119 ?"
and likewise the postback variable will be 119 instead of 120-01.

Any suggestions?

Thanks,
Max
Aug 25 '05 #1
2 3199
It looks like you're missing the quotes around the filename.

Instead of this:
<a href=\"javascript:confirm_entry($id[0],$dir_count\">Delete</a>

do this:
<a href=\"javascript:confirm_entry('$id[0]',$dir_count\">Delete</a>

Brian.
Max wrote:
I'm reading some files in a directory using php code for the end result of
allowing these files to be deleted.

The problem is some of the file names have hyphens in them, and this cannot
be changed.

The php code prints each file name on a page and has a delete link for each
seperate file. I pass the name of the file via a variable using onclick to a
javascript confirm function when the delete link is clicked on. But when the
javascript confirm dialog box appears and asks 'Are you sure you want to
delete file xxxx', if the file name was for example 120-01, the javascript
dialog would display will display 119 instead.

How can I get around this? I started to read something about using brackets,
but I can't seem to get it working.

Here is the relevant code:

Let's say $id[0] = "120-01";

print " <td style=\"background-color:silver\" width=\"5%\"
align=\"center\"><b><a href=\"javascript:confirm_entry($id[0],$dir_count
\">Delete</a></b></td>";
<script language=\"JavaScript\">

function confirm_entry(id,dir_count) {
input_box=confirm(\"Are you sure you want to delete MTR ID \"+id+\" ?\");
if (input_box==true) {

window.location = \"$self?delete=\"+id+\"?dircount=\"+dir_count

}
}
</script>
The confirm will end up as "Are you sure you want to delete MTR ID 119 ?"
and likewise the postback variable will be 119 instead of 120-01.

Any suggestions?

Thanks,
Max


Aug 25 '05 #2
Max wrote:
I'm reading some files in a directory using php code for the end result of
allowing these files to be deleted.

The problem is some of the file names have hyphens in them, and this cannot
be changed.

The php code prints each file name on a page and has a delete link for each
seperate file. I pass the name of the file via a variable using onclick to a
javascript confirm function when the delete link is clicked on. But when the
javascript confirm dialog box appears and asks 'Are you sure you want to
delete file xxxx', if the file name was for example 120-01, the javascript
dialog would display will display 119 instead.

How can I get around this? I started to read something about using brackets,
but I can't seem to get it working.

Here is the relevant code:

Let's say $id[0] = "120-01";

print " <td style=\"background-color:silver\" width=\"5%\"
align=\"center\"><b><a href=\"javascript:confirm_entry($id[0],$dir_count
\">Delete</a></b></td>";
When posting, it is much better to post the actual code that the client
gets, not what you are programming on the server.

I'll guess that the client is getting:

<a href="javascript:confirm_entry( 120-01, ... ">

Firstly, the href should point to something useful, otherwise browsers
with scripting disabled or not implemented will see a link that does
nothing. Add the script as an onclick event:

<a href="deleteID.html?120-01" onclick="confirm_entry( 120-01, ... ">

Secondly, the hyphen is being interpreted as a minus sign so the first
parameter passed to 'confirm_entry' will be the number 119. Enclosing
the characters in quotes will make the parameter the string '120-01'.

Thirdly, if '120-01' is the id of an element (it may not be, I'm just
guessing that maybe it is), then it is an invalid id - they must start
with a letter, but can include numbers.

<URL:http://www.w3.org/TR/html4/struct/global.html#adef-id>


<script language=\"JavaScript\">


The language attribute is depreciated, type is required:

<script type="text/javascript">

[...]
--
Rob
Aug 25 '05 #3

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

Similar topics

27
31362
by: The Bicycling Guitarist | last post by:
Hi. I found the following when trying to learn if there is such a thing as a non-breaking hyphen. Apparently Unicode has a ‑ but that is not well-supported, especially in older browsers. Somebody...
13
49841
by: Matt | last post by:
I would like to set the "list-style-type" to be a hyphen (-). How can I accomplish this in a style sheet. I tried list-style-type: hyphen; and list-style-type: dash; but neither worked. I also...
22
7975
by: stevenkobes | last post by:
If a word has a hyphen in it, IE will permit a line break at the hyphen, but Firefox/Mozilla won't. Apparently the Firefox behavior is standards-compliant, but it is not what I want. Is there a...
19
2114
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit...
4
4536
by: Rubin | last post by:
1) I want to show a breaking hyphen in Mozilla 1.5.0.4 How do I do that? "Unicode standard annex #14", <http://www.unicode.org/reports/tr14/>, defines 4 breaking hyphens. <quote> Breaking...
9
1804
by: David | last post by:
Hi, I have a field in a select query: 'Metal-XS' which is causing a problem The recordset should look like: RS2("Metal-XS") but it says this does not exist, and I cannot get the SQL to work in...
20
2678
by: junky_fellow | last post by:
Hi, In my previous post I asked if sizeof may be implemented as a function. Somebody pointed a link that says that sizeof may calculated as follows with a warning that it is not guaranteed to...
6
7785
by: Kc-Mass | last post by:
In a standard Ascii table a dash or hyphen is decimal 45. A period or dot is decimal 46. If I sort a table or recordset of mixed character string ascending in Access, those strings beginning with...
3
3989
by: Joe Stateson | last post by:
I have a template field that contains filenames that are (or can be) on a unix system. The hypen (and others) is a valid filename character in unix. When I display the name of the file I get an...
0
7267
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,...
0
7175
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...
1
7120
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...
0
7542
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...
0
5697
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,...
0
3247
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...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
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 ...
0
466
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...

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.