473,507 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


HELP!

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
randelld

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

<body>
<script type="text/javascript">
function firstFunction(formName)
{
// Read in arguements passed to the function from the onClick event in the
forms submit button
var argv = firstFunction.arguments;
var argc = firstFunction.arguments.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
value
var xyz=document.forms[formName].elements['firstname'].value;
document.write(" xyz = " + xyz);

// Simplify our form data object name in to formData
var formData=document.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
fieldName=argv[count];
// 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
tmpc=argv[count+1];
// 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.elements[fieldName].value;
// tmpe=document.forms[formName].elements[fieldName].value;
// tmpe=document.forms[formName].elements['firstname'].value;
document.write("<hr>tmpe=" + tmpe);
// Brace below closes the for loop
}

// Brace below closes the function
}

</script>

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

THANKS!
Jul 20 '05 #1
1 5998

"Randell D." <re**********************@and.share.com> wrote in message
news:xpuwb.488431$9l5.457359@pd7tw2no...
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

2
12861
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" > ...
1
1345
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...
2
5788
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...
2
2893
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...
5
3713
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....
27
4583
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 =...
2
4642
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...
2
3364
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...
2
1225
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...
0
7223
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,...
0
7321
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,...
1
7034
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...
0
5623
agi2029
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,...
1
5045
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...
0
4702
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
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 ...
0
412
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...

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.