PDA

View Full Version : autofill forms and dynamic url's


usedtextbook
08-15-2002, 02:22 AM
I have looked all over for answers to this problem...

I want all input box's (Form Submit Fields) to auto fill in when one or any one has data put in. For example: you type in 'hello' into a form field, then all form fields on the page (20 or so for example) will then show "hello".


So when someone enters their title for a search on usedtextbook.com all they have to do is click on submit.

Thanks in advance!

joh6nn
08-15-2002, 03:10 AM
maybe i just don't get what it is that you're after, but if you're going to have 20 or so fields, and they're all going to have the same thing in them, then why not just have the one field, with the one variable in it?

adios
08-15-2002, 03:14 AM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

function popAll(tBox) {
for (var el, i=0; el=tBox.form[i]; ++i)
if (el != tBox && el.type == 'text') el.value = tBox.value;
}

</script>
</head>
<body>
<form>
field 1: <input type="text" name="field1" onkeyup="popAll(this)"><br>
field 2: <input type="text" name="field2" onkeyup="popAll(this)"><br>
field 3: <input type="text" name="field3" onkeyup="popAll(this)"><br>
field 4: <input type="text" name="field4" onkeyup="popAll(this)"><br>
</form>
</body>
</html>

usedtextbook
08-15-2002, 11:01 AM
joh6nn: the value of that variable is dependant on each and every user that visits the site. for example, user one might enter 'mark twain' while user two might enter 'ayn rand'. the value 'mark twain' (or whatever), after it is entered into any text box (or a single main text box), has to be populated into all other text box's

adios: thats what I am after! BUT if I isolate the field1: field2: field3: field4: with a <form></form>, as in if every field that needs to be populated is in its own unique form, it doesnt work. Each field has to be in its own form

Thanks again in advance for your time

Lee Brenner
08-15-2002, 04:25 PM
.
.
.

function populateAll(which){
for(i = 1; i <= document.forms.length; i++)
eval("frm" + i + ".text" + i).value = eval("frm" + which + ".text" + which).value;
}

.
.
.

<form name="frm1">
<input type="text" name="text1" value="something" onchange="populateAll(1);">
</form>
<form name="frm2">
<input type="text" name="text2" value="something" onchange="populateAll(2);">
</form>
<form name="frm3">
<input type="text" name="text3" value="something" onchange="populateAll(3);">

.
.
.

Enjoy!

adios
08-15-2002, 05:37 PM
function popAll(tBox) {
for (var f=0; form=document.forms[f]; ++f)
for (var el, i=0; el=form[i]; ++i)
if (el != tBox && el.type == 'text') el.value = tBox.value;
}

Hard to guarantee anything like this, because of platform inconsistencies with keystroke handling. Cool, though.

Might want to try onblur in place of onkeyup.

joh6nn
08-15-2002, 08:06 PM
what i meant was, if the user is going to type in one field, and then whatever he inputted, is populated into 19 other fields, why have 19 other fields? just have one field for him to type something into. otherwise, you end up with 20 variables, that all have the same value in them.

usedtextbook
08-16-2002, 01:01 AM
joh6nn: all 20 or so forms are unique (all different bookstores with unique form info), and each may or may not be clicked on. check out usedtextbook.com and you will see what I mean.

adios: your second script didn't work untill I saw the <form name="frm1"> part that needed to be added, as well as other form stuff that needed to be changed.

lee brenner: yours 'half way' worked at first, the text box's would populate with text only when you clicked on them. Changing 'onchange' to 'onkeyup' (from adios's first script) fixed that.

Thanks again all!

usedtextbook
08-16-2002, 02:00 AM
well I went to modify my existing page adding the new code, but the forms didn't like having their names changed...

changing:

<FORM action="http://click.linksynergy.com/fs-bin/statform" METHOD="GET">
<INPUT type="text" name="keywords" size="21">

to:

<FORM action="http://click.linksynergy.com/fs-bin/statform" METHOD="GET" name="frm1">
<INPUT type="text" name="text1" value="" size="21" onkeyup="populateAll(1);">

made the search box's populate, but broke the search itself because the other side expects the form name to be 'keywords' or 'stext' or 'search' or 'xyz'. They have to stay these values. Any Ideas?

adios
08-16-2002, 03:45 AM
usedtextbook...

Have no idea. I didn't use any form names - that's the whole point of these types of object-based routines - and your response earlier didn't seem to be connected to what I posted (<form name="frm1">???). Is this another Q. entirely (by 'other side' I'm guessing you mean the server).

:confused:

usedtextbook
08-16-2002, 10:14 AM
when I use your script:

<script type="text/javascript" language="javascript">

function popAll(tBox) {
for (var f=0; form=document.forms[f]; ++f)
for (var el, i=0; el=form[i]; ++i)
if (el != tBox && el.type == 'text') el.value = tBox.value;
}

</script>

on a webpage by itself, it works perfectly. however when i put that exact same script into my existing webpage i get an error:

line: 10
char: 15
error: Object does not support this property or method
Code: 0
Url: ... testindex.html

i cnage nothing, just cit and paste the script into the head /head section. i tried it in the body /body part too for fun, didnt work either. same error.

stumped

whatinspiresu
05-20-2006, 01:48 AM
This is neat.

Im looking for a variation of this and wondered if anyone knew how to do it. I want to have a form with say 4 fields in one frame - that will pop the same information into another form in a different frame or an iframe, on submit (and also remember the information in the first form).

Big kiss to anyone that can give me this code.

Trisha



<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

function popAll(tBox) {
for (var el, i=0; el=tBox.form[i]; ++i)
if (el != tBox && el.type == 'text') el.value = tBox.value;
}

</script>
</head>
<body>
<form>
field 1: <input type="text" name="field1" onkeyup="popAll(this)"><br>
field 2: <input type="text" name="field2" onkeyup="popAll(this)"><br>
field 3: <input type="text" name="field3" onkeyup="popAll(this)"><br>
field 4: <input type="text" name="field4" onkeyup="popAll(this)"><br>
</form>
</body>
</html>