/    Sign up×
Community /Pin to ProfileBookmark

form autofill(with extra bit)

Hi
I’m building a form that is going to a database, I have 2 parts to the form that are very important, Field one is Input field called product name which is straight forward:
example:
product name: Mountain Bike

what i reqiure the form to do is once you have entered the Product in to that field it adds that to the next field automatically and replacing the space between Mountain Bke with a underscore and all to lower case like so mountain_bike.

I’ve seen it done but can’t figure out from the very complex why the site is set up how it’s done.

Does anybody know how to do this using javascript

Cheers

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledJan 27.2008 — basically to do the conversion you need regular expression and string method toLowerCase:

<i>
</i>var my_string = 'My Product Name'.toLowerCase().replace(/s+/g, '_');
// my_string now contain my_product_name string


when applied to a form, code may vary according to form setup. let assume you have ths form:
[code=html]
<form id='product_form'>
<input type='text' name='product' onchange='underscoreCase(this.form)' />
<input type='text' name='product_clone' />
</form>
[/code]


<i>
</i>function underscoreCase(form){
form.product_clone.value = form.product.value.toLowerCase().replace(/s+/g, '_');
}
×

Success!

Help @Tea_Break 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.6,
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,
)...