473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving form values in Javascript

Hi everyone,

I am trying to create a form for authorised users to upload photos to
an image gallery. I'm attempting to perform simple validation of the
fields by ensuring the fields aren't empty and that the extensions are
right. However, I can't seem to access the actual values of the fields
to start with.

If I simplify my problem, can anyone tell me why this would work in a
Javascript alert:

alert(document. form.Photo1.val ue);
//This outputs 'D:/images/x.jpg'

but this won't:

var photonumber = "Photo" + 1;
alert(document. form.photonumbe r.value);
// I get "undefined"

The reason I'm doing this is because I'm looping through a finite set
of images and need to check each one is valid.

Is it because I'm not initialising the "photonumbe r" string correctly?

If there are any geniuses out there, please help this newbie.

Thanks in advance!

Nat.

Sep 29 '06 #1
4 5299

naman...@gmail. com wrote:
Hi everyone,

I am trying to create a form for authorised users to upload photos to
an image gallery. I'm attempting to perform simple validation of the
fields by ensuring the fields aren't empty and that the extensions are
right. However, I can't seem to access the actual values of the fields
to start with.

If I simplify my problem, can anyone tell me why this would work in a
Javascript alert:

alert(document. form.Photo1.val ue);
//This outputs 'D:/images/x.jpg'

but this won't:

var photonumber = "Photo" + 1;
alert(document. form.photonumbe r.value);
// I get "undefined"
>From your description it sounds like the most likely place it is
causing an error is in Internet Explorer. That is because you are
using a variable name that is the same as the form name. Try a
different variable name.

Sep 29 '06 #2
web.dev said the following on 9/28/2006 9:11 PM:
naman...@gmail. com wrote:
<snip>
>but this won't:

var photonumber = "Photo" + 1;
alert(document .form.photonumb er.value);
// I get "undefined"
>>From your description it sounds like the most likely place it is
causing an error is in Internet Explorer. That is because you are
using a variable name that is the same as the form name. Try a
different variable name.
No, it is because there is no form element named "photonumbe r", and it
won't replace the variable with it's value in dot notation. What will
work however is something like this:

document.forms['form'].elements[photonumber].value

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 29 '06 #3
JRS: In article <11************ **********@b28g 2000cwb.googleg roups.com>,
dated Thu, 28 Sep 2006 17:18:30 remote, seen in
news:comp.lang. javascript, na******@gmail. com posted :
>var photonumber = "Photo" + 1;
alert(document .form.photonumb er.value);
// I get "undefined"
>If there are any geniuses out there, please help this newbie.
One only needs the ability to read the newsgroup FAQ, 2.3, 4.41 & 4.39;
see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 30 '06 #4
Thanks to everyone who replied.

I got it to work by doing the following:

alert(document. form.elements[name].value);

Nat.
Dr John Stockton wrote:
JRS: In article <11************ **********@b28g 2000cwb.googleg roups.com>,
dated Thu, 28 Sep 2006 17:18:30 remote, seen in
news:comp.lang. javascript, na******@gmail. com posted :
var photonumber = "Photo" + 1;
alert(document. form.photonumbe r.value);
// I get "undefined"
If there are any geniuses out there, please help this newbie.

One only needs the ability to read the newsgroup FAQ, 2.3, 4.41 & 4.39;
see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 1 '06 #5

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

Similar topics

1
1799
by: Chris Shipley | last post by:
I am trying to present a list of links on a page (Form) where each link opens a different picture gallery. I have the Form page which contains the links, a Gallery page, and several include files. Each include file displays a different gallery. Clicking on a link submits a value identifying the chosen gallery to the Gallery page. The Gallery page accepts the value from the Form page and uses it to call the appropriate include file. The...
3
6789
by: CES | last post by:
All, Is their a way of iterating thru each tag within a form and returning the value given in the id property, by that I mean the below html would return the values idBoxOne, idBoxTwo, idBoxThree from the FormXX form. <form name="FormXX" method="post" action="default.htm"> <input id="idBoxOne" name="bxOne" type="text"> <input id="idBoxTwo" name="bxTwo" type="text"> <input id="idBoxThree" name="bxThree" type="text">
1
1539
by: Captain Dondo | last post by:
I am not really experienced in Javascript so bear with me.... I am working with an embedded platform; no mouse, no keyboard. Just up, down, left, right keys and +/- keys for incrementing/decrementing the vaules in the form. So my website consists of forms... Each form has a number of columns and rows. I am generating each page using a php script and some templates. Because the exact layout of each page can change based on customer...
10
3701
by: Girish | last post by:
Hi Everyone, I am passing a form to a php script for further processing. I am able to retrieve the last value set for that given form variable using $variable=$_REQUEST;
2
2008
by: 4Ankit | last post by:
hello all, i am having some difficulty retrieving information from my form. I want to add content in my table but the content i want to add to the table is what the user inputs in my form. Basically i want to know how i retrieve information from the form so i can disaply it in the table. i have put the code i am using below, the feature i cannot get to work is the change content function. I want the email address entered by the...
2
1442
by: prabu507 | last post by:
hi , please if u know the answer reply ..... the question is i m having a form and a button control if i enter the password field then after clicking the button it should call a javascript function where the password got encrypted and the encrypted value should be asigned to the same text field and then it should submit the values..to the same page. after submitting we have to decrypt the password and i...
0
3398
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
4
1709
mehj123
by: mehj123 | last post by:
Hi... I have written some cgi scripts and I need to pass the user id and password between them.. There is a Login page which passes the user name and password to another cgi script through the url which in turn encrypts it and passes it to the next cgi script (again through url). The third cgi script is also able to retrieve the values (using the param method), it adds another variable to the url and passes to the next cgi script.. The...
4
1551
by: ton | last post by:
Hi, I'm using Ajax (AjaxPro) this works fine. (In vb.net) To get update several controls I connect the server and these controls are updated. When saving these values I use aa=page.request("TextboxID") which gives me the modified Text property in case of a combobox i get with this method the selectedkey value. Great !!
0
9673
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
10217
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
10168
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
10003
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...
1
7546
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...
0
5440
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
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.