This is a discussion on "Form value shows as Undefined" within the JavaScript Forum section. This forum, and the thread "Form value shows as Undefined are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Form value shows as Undefined
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
I have a form that is a basic user details address etc... There are 3 address fields on the form, 2 are required and one is optional. When the form is submitted, the following (confirmation) page shows "Undefined" where the empty 3rd address field is passed in. How can I use javascript in the confirmation page to ignore the address3 variable if it is empty or null?
All I can get it a blank line in between the address information like so: Name This House This Street undefined This Town This County Postcode Where what I would like is: Name This House This Street This Town This County Postcode If there was a 3rd address line, this still needs to be shown in the confirmation page. This may be a really simple thing, but I'm a bit new to this - sorry! |
|
|
|
|||
|
Re: Form value shows as Undefined
It's probably not a question of using JavaScript. How are you processing the form information?
|
|
|||
|
Here's the code in a simple page, the passed values would be for example: "Address1=The+Cottage&Address2=The+Street&Address3 =&Town=The+Village"
[CODE START] <html> <head> <title>Test</title> <script language="JavaScript"> function parseGetVars() { var getVars = new Array(); var qString = top.location.search.substring(1); var pairs = qString.split(/\&/); for (var i in pairs) { var nameVal = pairs[i].split(/\=/); getVars[unescape(nameVal[0])] = unescape(nameVal[1]); } return getVars; } </script> </head> <body> <script> var g = parseGetVars(); for (var i in g) document.writeln(g[i].replace(/\+/g,' ').replace(/\undefined/g,'')+'<br>'); </script> </body> </html> [END CODE] I don't know if this is the most elegant way to do this, but I just can't get the values to display without either an undefined or blank entry. I need some sort of 'if (Address3 == null)' skip to next value? Pete. |
|
|||
|
Re: Form value shows as Undefined
I'm still not entirely clear what exactly you are trying to do. Are you able to post links to your page so that we can see the full story? Is the idea that the end user fills in the details, submits the form and the details come to you in the form of an email or are you trying to retrieve someones details from, for example, a database and display them on the page?
|
|
|||
|
Re: Form value shows as Undefined
It's nothing quite so advanced. The ultimate aim is to produce a printable order form for a book by getting the visitor to input their details to a form on the web site (Not yet live). This form will validate the content and make sure they don't leave any essential information out. When this gets submitted, a new page should appear that is set out in printer friendly format - showing the name and address info and order information etc...
I just want the name and address portion to display without blanks or the word "undefined" appearing when the visitor has not got a 3rd address line as it is optional. I would like the name and address info to appear in just 1 column. Pete. |
|
|||
|
Re: Form value shows as Undefined
Give your fields id's and use css to hide unwanted fields. The processing would be something like:
|
|
|||
|
Re: Form value shows as Undefined
Ok. Sorry to be a dummy, but on which page do I do this, the form or the receiving page? How do I create a function for this and where do I call it from?
Pete. |
|
|||
|
Re: Form value shows as Undefined
Quote:
|
|
|||
|
Re: Form value shows as Undefined
The form is submitted with a GET method.
Pete. |
|
|||
|
Re: Form value shows as Undefined
Looking at what you have provided, the job needs to be taken care of in 'printform.htm'.
But there are lots of things you need to take care of: Code you file to some DTD standard. Use only lowercase letters for your tag names, etc. Don't use GET to submit form information as it shows up in the address bar. Use POST. I'm still not sure where your going with all this but it looks like you need to consider some form of server side coding. |
![]() |
| Tags |
| form, value, shows, undefined |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Undefined Index error with DB | Sphinx111 | PHP Forum | 3 | Apr 21st, 2008 20:37 |
| Undefined index problem | andrewlondon | PHP Forum | 12 | Sep 2nd, 2007 12:19 |
| Another with IE woes - Element is undefined | weasel | Web Page Design | 3 | Jul 5th, 2007 18:18 |
| Undefined variable: row | csun | PHP Forum | 3 | Jun 5th, 2007 12:44 |
| Undefined index using $GET_ | LostProphet | PHP Forum | 7 | Aug 22nd, 2006 11:15 |