473,856 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple js dynamically reading form values - js fails - why?


I am determined to stick with this... I'm getting there... for those who
haven't read my earlier posts, I'm createing what should be a simple
function that I can call to check that required fields in a form have
values. I'm writing the values to the client using document.write only so
that I can confirm that the values are there to be played with - this is not
the final result so please (unless it's leading to the script failure)
please ignore layout - I don't need to hear about the <br> or CSS or
anything else that looks nice - I'm working on basic program flow at the
moment.... Oh! and note I'm a javascript newbie comming - I have some
progarmming experience with PHP which I would have thought would have helped
me along a bit...

So... Can someone help my next step? In my script below, it draws a basic
form - The theory behind it is once values have been written in to the two
form fields and the user presses the submit button, I would expect to have
the form values re-gurgitated (?) back on to the screen (again, just to
prove that the values are visable inside firstFunction()

I want the script to be dynamic - Thus, from an onclick event on the submit
button, the function is called and passed the form name, a required form
field (as named inside the "<INPUT>" html tag), followed by the 'real name'
of the tag that the user gets to see in the browser. Thus... the idea being
that if the input tag 'firstname' has no value, an alert box will popup
asking for a value for "First Name" and not "firstname' .

My problem?

If you examine the script, variable xyz gets assigned the firstname entered
in the form - This is proven (ie displayed using document.write) .

The next step is to create a loop that would read the supplied arguements to
read values from the form. Thus... my example would be form fields
'firstname' and 'lastname'...

What is done are the arguements passed to the function are displayed (these
are the form field tag names). And when I try to use these values (see
variable tmpe in the script) to display form field values, the script
exits - no errors - nothing. When I exclude 'tmpe' from the script, the
script completes by looping twice (since the function was passed two field
names)... but I cannot use the form field names dynamically within the
loop... why?

All help, via the newsgroup (share+help others) is much appreciated, thanks

My script (also at http://www6.wiredwords.net/test/e.html)

<script type="text/javascript">
function firstFunction(f ormName)
// Read in arguements passed to the function from the onClick event in the
forms submit button
var argv = firstFunction.a rguments;
var argc = firstFunction.a rguments.length ;
// The document.write below *did* work earlier - Now the script exits when I
include it - why?
// document.write( "argc = " + argc);

// Can we read anything from the form? Try a hard code reading of a form
var xyz=document.fo rms[formName].elements['firstname'].value;
document.write( " xyz = " + xyz);

// Simplify our form data object name in to formData
var formData=docume nt.forms[formName];

// Define tmpe - for our test purposes, we assign a dash as a value just so
that we know
// it has a value
var tmpe="-";

// Loop through the numbre of arguements passed to firstFunction() - Read
from the second arguement
// since the first arguement is formName
for(count=1; count<argc; count=count+2)
{ // Simplify our form field name in to a single variable
// Again, for the hell of it, confirm fieldName is valid by making
note of its length
tmpb=fieldName. length;
// tmpc is the user friendly name of a field - thus it has a value of
First Name as opposed
// to the html tag name firstname
// Dump our values to the screen, one per line to make things easier
to read.
document.write( "<hr>count= " + count + "<hr>fieldName= " + fieldName
+ "<hr>tmpb=" + tmpb + "<hr>tmpc = " + tmpc );

// I have tried the following methods to define a value for tmpe but
they fail -
// What is the correct syntax and if possible, why does it fail?
// tmpe=formData.e lements[fieldName].value;
// tmpe=document.f orms[formName].elements[fieldName].value;
// tmpe=document.f orms[formName].elements['firstname'].value;
document.write( "<hr>tmpe=" + tmpe);
// Brace below closes the for loop

// Brace below closes the function


<form name="myForm">
<br>Firstname : <input type=text name=firstname size=30> Lastname: <input
type=text name=lastname size=30>
<input type="submit" onclick="firstF unction('myForm ','lastname','L ast
Name','firstnam e','First Name'); return">
<hr><a href="./e.html">again</a><hr>

Jul 20 '05 #1
1 6031

"Randell D." <re************ **********@and. share.com> wrote in message
news:xpuwb.4884 31$9l5.457359@p d7tw2no...
I got it... in a previous post I had been told not to use document.write and
use alert() instead - I was told that using document.write was ineffiicient
but I had not realised that it was causing my problems...

I've written my scrpit exactly the way I'd like it to work - thanks to all
who helped...
Jul 20 '05 #2

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

Similar topics

by: juglesh | last post by:
hi, all, thanks for reading. i have a form in which i want drop down boxes to dynamically change some hidden fields: http://cynthialoganjewelry.com/test4.htm <form name=test method="post" > Pearl Color: <select name="product1">
by: imxuf | last post by:
I have an Active Server Page with embedded Javascript that allows th user to update certain values dynamically. e.g. window.document.myForm.myTextbox.value = "some new value"; However, when the user clicks Submit and the Form is processed on th server, the Request object doesn't recognize the new values set by th Javascript code. The values come back as "". Has anyone seen this behavior? How can it be rectified?
by: Stephen Miller | last post by:
When I dynamically populate a HtmlSelect combo box, the Value property consistently fails to return the item selected, defaulting instead to the first item in the list. For example: Protected WithEvents Fruits As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Results As System.Web.UI.WebControls.Label Protected WithEvents Button1 As System.Web.UI.WebControls.Button … Private Sub Page_Load(ByVal sender As System.Object, ByVal...
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to avoid the problem by avoiding the table control or resorting to databound controls that better manage state for me. I hope to understand how to solve the problem by using the Table web control and sticking to the approach of building the table at run...
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of controls to the webpage using the innerHTML method. It appears to work perfectly fine in the browser. The...
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
by: somaskarthic | last post by:
Hi In my php code , i dynamically created table rows on button click event. Each row contain 3 selectboxes, 7 checkboxes . On each click of these elements i need to submit the form and save the data to database. After each submit , i need to display the previous added details (with some checkboxes checked and some others unchecked ..) and one new row for next updation. Here i need to collect all values submitted in the php page. There i...
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and place it in the last cell of each row that I create dynamically using DOM methods. Everything is working well (that is, just like the original example) except for something related to the function behind my link. The link simply calls a function...
by: Jack | last post by:
Hi there, I'm a very experienced C++ developer but a relative newcomer to web development and a raw neophyte in the ASP.NET arena. I have a very simple scenario that hopefully someone can help me with. I have a 3rd-party HTML form with a single (submit) button and a number of (static) hidden fields (all values hardcoded). The form is pure HTML (no ASP or ASP.NET whatsoever) and it simply posts its data to a 3rd-party site when the button...
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...
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...
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...
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,...
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...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.