Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill forms.

Status
Not open for further replies.

sansti

Programmer
Jul 8, 2000
1
DK
I have a huge form and I often hav to write down phonenumbers etc. over and over again.<br>Can anyone show me how to write:<br><br>----------------------------------------<br>&lt;input name=&quot;name&quot; size=&quot;30&quot;&gt;<br>&lt;%<br>If name = &quot;john&quot; then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phone = &quot;555 78645 74&quot;<br>ElseIf name = &quot;James&quot; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phone = &quot;554 48752 12&quot;<br>End If<br>%&gt;<br>&lt;input name=&quot;phone&quot; value=&quot;&lt;%=phone%&gt;&quot;&gt;<br>----------------------------------------<br><br>in Javascript ???<br>So when you type &quot;John&quot; in tha name-box then the phone-box value will be &quot;555 78645 74&quot;.<br>Kind of &quot;autofill&quot; function..<br>I need it to be dynamic.<br><br>SS<br><br><br>
 
Well would you mind if the test ran as soon as focus was taken away from the name textbox?<br><br>you could have something like this (I'm not sure what the name for removing focus would be in this case- I'm guessing it's &quot;blur&quot;, but somebody else can correct my syntax if it's incorrect):<br><br><FONT FACE=monospace>&lt;HEAD&gt;<br>&lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;<br>&nbsp;&nbsp;&lt;!--<br>&nbsp;&nbsp;&nbsp;&nbsp;function numberReplacer(name) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (name == &quot;John&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.form.phone.value = &quot;555 78645 74&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (name == &quot;James&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.form.phone.value = &quot;554 48752 12&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;//--&gt;<br>&lt;/SCRIPT&gt;<br>&lt;/HEAD&gt;<br>&lt;BODY&gt;<br>&lt;FORM&gt;<br>&lt;INPUT NAME=&quot;name&quot; SIZE=&quot;30&quot; onBlur=&quot;numberReplacer(this.value);&quot;&gt;<br>&lt;INPUT NAME=&quot;phone&quot;&gt;<br>&lt;/FORM&gt;<br>&lt;/BODY&gt;<FONT FACE=monospace><br><br>that should just about do it.. if you get any errors, they are likely to be syntactical- I'm sure somebody else who deals with JavaScript more (or maybe somebody who has a link to a good DOM tutorial? hint hint) can clean it up. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top