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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using form data within a page without first submitting it...

Status
Not open for further replies.

kmurrah

Programmer
Jul 4, 2001
4
US
Pardon the elementary question, but ...

Is it possible to use data collected in a form ON THE SAME PAGE without
using the form's "submit" button? In other words, if a text field is filled
in, can I capture the info typed there and display
it elsewhere on the same page?

I know this must be REALLY simple to you folks, but if you could point me in the direction of a tutorial or whatever that would address my problem, I would really really really appreciate it.

thanks in advance,

kenn
 
Kenn,

Not being a master at javascript, here are a couple of solutions in this script:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<form name=form1>
<input type=text name=field1 value=&quot;&quot; onblur=&quot;writeval(this)&quot;><br>
<input type=text name=field2 value=&quot;&quot; onblur=&quot;javascript:document.write(this.value)&quot;><br>
<input type=text name=field3 value=&quot;&quot; >
</form>
<script language=javascript>
<!--
function writeval(field){
document.form1.field3.value=field.value;
}
-->
</script>
</BODY>
</HTML>

Field1 will populate field3. field2 will rewrite the page. Hope this helps. Of course, if anyone else has any suggestions, how do you get field2 to not rewrite the page???

Mike
 
yes you can do so - remember javascript is CLIENT side so it doesn't need to access the server to do stuff (that's mainly the interest in using javascript)

say your form is
<form name=formname ....>
...
<input type=text name=inputname ....>
....
</form>

now you can call the data entered in inputname with :
document.formname.inputname.value

for example, say the event to alert the data is the click on a button
<form name=formname ....>
...
<input type=text name=inputname ....>
<input type=button value=&quot;click me&quot; onclick=&quot;javascript:alert(document.formname.inputname.value)&quot;>
....
</form>

ok ?
now it depends on what you want to do - alert the value, display it ... and on the type of the value (you don't retrieve a &quot;select&quot; value as you would for a &quot;text&quot; one) ... and on the browser you're targetting
but those are easy and minor adaptations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top