473,662 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript and []

<form name=f>
<input type=text name="apple[]" value=1>
</form>

<script>
document.f.appl e[].value=2
</script>

///////////////////////////
this generates an script error in IE
because of apple[]
so how do I get around the error?
(must use "apple[]" for server cgi)

thanks in advance :)


Jul 23 '05 #1
5 1336
document.getEle mentsByName("ap ple[]") //returns an object array

--
www.vicdir.com
<ap***@apple.co m> дÈëÓʼþ news:cc******** **@news.seed.ne t.tw...
<form name=f>
<input type=text name="apple[]" value=1>
</form>

<script>
document.f.appl e[].value=2
</script>

///////////////////////////
this generates an script error in IE
because of apple[]
so how do I get around the error?
(must use "apple[]" for server cgi)

thanks in advance :)

Jul 23 '05 #2
wrote on 11 jul 2004 in comp.lang.javas cript:
<form name=f>
<input type=text name="apple[]" value=1>
</form>

<script>
document.f.appl e[].value=2
</script>


<form name=f>
<input type=text name="apple[]" value=1>
</form>

<script type="text/javascript">
document.f[0].value=2 // the first child of f
</script>

========= or ==========

<form name=f>
<input type=text name="apple[]" id=appl value=1>
</form>

<script type="text/javascript">
document.getEle mentById('appl' ).value=2
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #3
ap***@apple.com wrote:
so how do I get around the error?
document.forms['f'].elements['apple[]'].value = 2;
(must use "apple[]" for server cgi)


Not really. I assume that you are using php, which also supports an
always_populate _raw_post_data directive.

With this directive enbled, you can simply use normal names and still use
arrays:

<form method="post" action="...">
<input type="checkbox" name="fruit" value="apple" /> Apple<br />
<input type="checkbox" name="fruit" value="banana" /> Banana<br />
<input type="checkbox" name="fruit" value="pear" /> Pear<br />
<input type="submit" />
</form>
.....
<?
if (!isset($HTTP_R AW_POST_DATA) ||
!strstr($HTTP_R AW_POST_DATA, 'fruit=')) {
print "Please select some fruits";
} else {
parse_str(
str_replace(
"fruit=",
"fruit[]=",
$HTTP_RAW_POST_ DATA
),
$fruits
);
print "Selected fruits:<br />";
foreach ($fruits['fruit'] as $fruit) {
print "$fruit<br />";
}
}
?>
JW


Jul 23 '05 #4
"Evertjan." wrote:
wrote on 11 jul 2004 in comp.lang.javas cript:
<form name=f>
<input type=text name="apple[]" value=1>
</form>

<script>
document.f.appl e[].value=2
</script>


<form name=f>
<input type=text name="apple[]" value=1>
</form>

<script type="text/javascript">
document.f[0].value=2 // the first child of f
</script>

========= or ==========

<form name=f>
<input type=text name="apple[]" id=appl value=1>
</form>

<script type="text/javascript">
document.getEle mentById('appl' ).value=2
</script>


document.forms['yourForm'].elements['apple[]'].value = 2;

Now you don't need to remember form input indices or use a
browser that is completely W3C compliant.

This is covered at <url: http://jibbering.com/faq/#FAQ4_25 />.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
"Janwillem Borleffs" <jw@jwscripts.c om> wrote in message news:<40******* *************** @news.wanadoo.n l>...
ap***@apple.com wrote:
so how do I get around the error?
document.forms['f'].elements['apple[]'].value = 2;
(must use "apple[]" for server cgi)


Not really. I assume that you are using php, which also supports an
always_populate _raw_post_data directive.

With this directive enbled, you can simply use normal names and still use
arrays:


[snip]
That would depend on if the compilation of your version of PHP
supports ALWAYS_POPULATE _RAW_POST_DATA. . you're safer using an array
construct, sorry.

<input type="checkbox" name="fruit[]" value="apple">A pple

in Javascript you would call this element cross-browser:
document.forms['myForm'].elements['fruit[]']

Phil

<form method="post" action="...">
<input type="checkbox" name="fruit" value="apple" /> Apple<br />
<input type="checkbox" name="fruit" value="banana" /> Banana<br />
<input type="checkbox" name="fruit" value="pear" /> Pear<br />
<input type="submit" />
</form>
....
<?
if (!isset($HTTP_R AW_POST_DATA) ||
!strstr($HTTP_R AW_POST_DATA, 'fruit=')) {
print "Please select some fruits";
} else {
parse_str(
str_replace(
"fruit=",
"fruit[]=",
$HTTP_RAW_POST_ DATA
),
$fruits
);
print "Selected fruits:<br />";
foreach ($fruits['fruit'] as $fruit) {
print "$fruit<br />";
}
}
?>
JW

Jul 23 '05 #6

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

Similar topics

0
8856
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8762
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
8545
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
8633
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
4179
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...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
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.