By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

problem with textfield name containing square brackets

P: n/a
Hi there

I'm hoping that someone can help me with a question I have about
javascript syntax.

I got an html page that uploads an image and some text field to a
database.

What I'd like to do is modify the content of one of the textfields
prior to it being submitted to the database. Specifically, I need to
append the contents of one of the fields to another.

The problem that I've encountered is that the textfield name contains
square brackets , ‘extra_fields[Price]'

I've identified the square brackets as being the problem by changing
the textfield's name to one that doesn't contain square brackets
,extra_fieldPrice for example and the script works fine.

Unfortunately, in the real world application of this page, I can't
change the textfield name.

The specific part of the html page that's giving me problems is
<input type="button" value="Click to generate code" class="body-text"
onClick="extra_fields[Price].value =
'$'+extra_fields[Price].value+'<br><A
HREF=&quot;../cgi-bin/processorder.cgi?'+caption.value+'~'+extra_fields[Price].value+'&quot;>Add
to Order</A>'"></input>
I've tried puting backslashes before the square bracket,

"onClick="extra_fields\[Price\].value =
'$'+extra_fields\[Price\].value+'<br><A
HREF=&quot;../cgi-bin/processorder.cgi?'+caption.value+……………….."
Unfortunately the script didn't still doesn't work though.

I'm not that familiar with javascript syntax. Can anyone suggest how I
can have javascript read square brackets as a literal part of a
textfield's name rather than as some kind of syntax modifier
The entire page's html is as follows

Thanks for any suggestions
<html>
<head>
<title>Add Item</title>

<script language="Javascript">
<!--
function reloadPage() {
document.count_form.submit();
return false;
}
// -->
</script>
</head>
<body>
<span class="popuphead">Add Photo</span>
<br>
<span class="popup">
Click the <b>Browse</b> button to locate a photo to upload.
<span class="admin">
<br>
&nbsp;&nbsp;(Supported file types: jpg, jpeg, gif, png, avi, mpg,
mpeg, wmv, mov, swf)
</span>

<br><br>

<form action="xxxxxxxxxx/products/add_photo.php" name="upload_form"
enctype="multipart/form-data" method="POST">
<input type=hidden name="" value="">
<input type="hidden" name="max_file_size" value="10000000">
<table>
<tr><td>
File</td>
<td><input name="userfile" type="file" size=40></td>
</tr>
<td>Caption</td>
<td> <textarea name="caption" rows=2 cols=40></textarea></td>
</tr>
<tr>
<td valign=top>Description</td><td><textarea
name="extra_fields[Description]" rows=2 cols=40></textarea></td
</tr>

<tr>
<td valign=top>Dimensions</td>
<td><textarea name="extra_fields[Dimensions]" rows=2
cols=40></textarea></td>
</tr>
<tr>
<td valign=top>Price</td>
<td><textarea name="extra_fields[Price]" rows=2
cols=40></textarea></td>
</tr>
</table>
<input type=checkbox name=setCaption checked value="1">Use filename as
caption if no caption is specified.
<br>

<input type="button" value="Click to generate code" class="body-text"
onClick="extra_fields[Price].value =
'$'+extra_fields[Price].value+'<br><A
HREF=&quot;../cgi-bin/processorder.cgi?'+caption.value+'~'+extra_fields[Price].value+'&quot;>Add
to Order</A>'"></input>

<input type="button" value="Upload Now"
onClick='opener.showProgress(); document.upload_form.submit()'>
<input type=submit value="Cancel" onclick='parent.close()'>

</form>

</body>
</html>
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Veverita" <mo***@email.com> wrote in message
news:d9*************************@posting.google.co m...
<snip>
The problem that I've encountered is that the textfield
name contains square brackets , 'extra_fields[Price]' <snip>Unfortunately, in the real world application of
this page, I can't change the textfield name.

<snip>

Real world applications should not be built using invalid HTML.

< URL: http://www.jibbering.com/faq/#FAQ4_25 >

- and -

< URL: http://www.jibbering.com/faq/#FAQ4_39 >

Richard.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.