473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Javascript-HTML elements

darksteel21
Hi to all,

Im seeking for a solution for my problem in javascript..how can i get the values of an unspecified number of html textfields using javascript??

The scenario is this:
The user will specify the number of fields he wants, for example he specified 3 textfields,then my script will generate 3 html textfields..i want to validate these three textfields before submitting the form,it should not contain NULL values..how should i do this?? hope someone could help me...
Jul 24 '08 #1
4 1151
r035198x
13,262 8TB
Write a generic validator that takes any input field and validates it according to your requirements. You then call that finction on each of your text boxes.
Jul 24 '08 #2
what do you mean by generic validator?please pardon me because im not that proficient in javascript...
But I have a script here to get the values of Html textfields:
[html]
<html>
<body>
<script language="JavaScript">
function function1() {
var m = document.getElementsByName("myE");
alert(m.length);
alert(m[0].name + "/" + m[0].value);
alert(m[1].name + "/" + m[1].value);
}
</script>

<form name="form1">
<input type="text" name="mytxt1" id="myE" value="">
<input type="text" name="mytxt2" id="myE" value="">
<input type="button"
value="Get the number of elements that have the same name"
onClick="function1();">
</form>
</body>
</html>
[/html]
it works fine on IE browsers..but not on firefox...
when you browse it on IE it detects 2 textfields, but on Firefox it only detects nothing...can you please explain me this problem?
Jul 25 '08 #3
rnd me
427 Expert 256MB
ids need to be different. names must be the same to use doc.getbyname
Jul 25 '08 #4
RamananKalirajan
608 512MB
Hi Dude, I hope this code will help you. But you have to enhance yourself to your need.

[HTML]<html>
<head>
<script language="javascript">
var choice;
function createText()
{
choice=parseInt(document.getElementById('user').va lue);
var textId;
for(var i=1;i<=choice;i++)
{
textId = "textId"+i;
var udiv=document.getElementById('myDiv')
var newEl=document.createElement('input');
newEl.type='text';
newEl.id = textId;
udiv.appendChild(newEl);
}
}

function validateText()
{
var textId
for(var i=1;i<=choice;i++)
{
textId = "textId"+i;
var temp = document.getElementById(textId).value;
if(temp=="")
alert('text '+i+' is null');
}
}
</script>
</head>
<div id='myDiv'>
</div>
<br/>
<input type="text" id='user'>
<br/>
<input type="Button" value="generate" onclick="createText()"><br/>
<input type="button" value="validate" onclick="validateText()">
</html>[/HTML]

Pls Post back your feedback. If you need more help i can help you out

Regards
Ramanan Kalirajan
Jul 28 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which...
6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
11
by: Doug van Vianen | last post by:
Hi, I often like to include some JavaScript coding in my web pages to make them more interesting. Unfortunately, even when this coding is as simple as a check to see what the display width is in...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
4
torquehero
by: torquehero | last post by:
Hi all :) I have created a horizontal navbar using Xara Menumaker. The Menu items have several dropdown menus. Its a javascript. When the mouse cursor is moved over any menu item, a dropdown...
18
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
10
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Which newsgroups deal with javascript? ----------------------------------------------------------------------- ...
34
by: dhtml | last post by:
I made a change to the FAQ of javascript to EcmaScript. I got some feedback that the newsgroup is CLJ and the language is commonly referred to as JavaScript. Therefore, the word in the FAQ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.