/    Sign up×
Community /Pin to ProfileBookmark

Applying validation on server created textboxes?

Hello forum

The Issue:

Lets say if a patient subscribed 5 medicines, then 5 textboxes will appear on the pharmacy page, n operator enter medicine qty and issue them. I m generating these text boxes with the same name, but how I take the refrence of these text boxes in javaScript, as these are virtual doesnt have physical code that I can access by document.forms.formName.txtName

how I apply text validation on dynamic textboxes,. wht the techniques u apply 2 handel this situation, plz help

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@KorJun 22.2006 — You can hadle all the document objects with javascript, nomatter if they are virtually or not. If they are server created they exist phisically (see view source). If they are client created, they still be handled, if they are created on using DOM methods.
Copy linkTweet thisAlerts:
@tahirakramchauthorJun 22.2006 — Yes u r right the code is generated but the issue is how I get the refrence of these controls here the example the way I m using

<i>
</i>while (patient.subscribedMedicine)
{
response.println ("&lt;input type= text name=qty&gt;");
}


here my all text boxes are generated if I try to access document.forms.formName.qty, give me nothing bcoz multiple textboxes has the same names. But if one textbox is created I got the reference.

Please share ur technique, thanx for replying
Copy linkTweet thisAlerts:
@KorJun 22.2006 — no problem, if you have more than a control with the same name, the reference will return a [B]collection[/B] (very much alike an array), thus you may find your elements upoin their index

var myEl=document.formName.qty;

for(var i=0;i<myEl.length;i++){

... do something with [B]myEl[i][/B].....

}



by the way, the correct ref is



document.formName.elemName

or

document.forms['formName'].elements['elemName']

or even

document['formName']['elemName']



u may also use DOM



document.getElemensByName('elemName') which will re3turn also a collection
Copy linkTweet thisAlerts:
@sridhar_423Jun 22.2006 — if you have a form name, then whatever Kor has said will be handy for you. but if your code doesnot permit in doing so, then try to atleast give the elements "id" attribute.

while (patient.subscribedMedicine)

{

response.println ("<input type= text name=qty id=qty>");

}

in your javascript function you can get the reference by

document.getElementById("qty");

but without a form name, what are going to do with the data?? I dont know if there's any method by which data gets posted without a form name. I never tried tat way..
Copy linkTweet thisAlerts:
@sridhar_423Jun 22.2006 — oops .. missed this one.. if this works, then there is no need of defining the "id" even..

[CODE]document.getElemensByName('elemName') which will re3turn also a collection[/CODE]
Copy linkTweet thisAlerts:
@KorJun 22.2006 — 

in your javascript function you can get the reference by

document.getElementById("qty");

[/QUOTE]


eeer, no, as id must be unique on document/session
Copy linkTweet thisAlerts:
@KorJun 22.2006 — oops .. missed this one.. if this works, then there is no need of defining the "id" even..

[CODE]document.getElemensByName('elemName') which will re3turn also a collection[/CODE][/QUOTE]


it works. It is even the only way to reach a radio button if it is single.
Copy linkTweet thisAlerts:
@tahirakramchauthorJun 22.2006 — thanks u ppl to guide me
Copy linkTweet thisAlerts:
@sridhar_423Jun 22.2006 — <BODY onclick="alert(document.getElementsByName('one').value)">

<input type="text" name="one" value="zebra">

</BODY>

? not working.. ""undefined"

i really tried if there's anything like this type.. getting reference with the help of element's name without using the form name ..

if this works, pls let me know where I'm going wrong..

i implemented this in the following way ..

append one counter variable to each of the elements name/id ..

use the same method in the javascript function also and get the reference ..

i=0;

while (patient.subscribedMedicine){

response.println ("<input type= text name=qty"+i+">");

}

document.getElementById("qty"+i).value

i++;
Copy linkTweet thisAlerts:
@KorJun 22.2006 — You have not read attentively my post. getElementsByName() returns a [B]collection[/B] (much alike to an array)

document.getElementsByName('one')[B][0][/B]
Copy linkTweet thisAlerts:
@sridhar_423Jun 22.2006 — woww.. works perfectly ..thnq vm.
×

Success!

Help @tahirakramch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...