/    Sign up×
Community /Pin to ProfileBookmark

Fill all the form fields

hi

Is there a way to fill all the form fields using javascript?
i want to test my forms and i am tired of being filling every field
eg.:

function fillform() {
//fill every form field
}
<body onload=”fillform();”>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoMar 21.2006 — It is easy enough to do, but you have to be more specific. Is your form al text fields, or are there checkboxes and option fields.
Copy linkTweet thisAlerts:
@amrigoauthorMar 22.2006 — i have 24 form fields

one textarea, many textboxes and checkboxes
Copy linkTweet thisAlerts:
@konithomimoMar 22.2006 — Use the code below. Just change form1 to the name of your form.
function fillAll()
{
var myform = document.form1;
var e = myform.elements;
var l = e.length;
for(var i=0;i&lt;l;i++)
{
if((e[i].tagName == 'textarea')||(e.type=='text'))
e[i].value='a';
else
e[i].checked = true;
}
return true;
}
Copy linkTweet thisAlerts:
@amrigoauthorMar 23.2006 — great!!

All the job is done using form.elements.lenght ...

cheers
×

Success!

Help @amrigo 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.2,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...