problem with textfield name containing square brackets

V

Veverita

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>
<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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top