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

can text be values 1

Status
Not open for further replies.

DrAsh

Technical User
May 3, 2001
46
US
Can values be represented by text. Such as, If I name a text form on my webpage to be test_taker, shouldn't anything someone writes in that box represent it's value. So than test_taker.value should be interpreted as John Myname or john_myname.value or test_taker.john myname.

If I wanted to take the information someone write in my text box to be recreated in another spot on my webpage. How can I do this then.

In others words, someone write their name on their exam in my text box. I want to set it up such that if that person passes the exam, that name/value he entered earlier, will get posted to a certificate on the same page. How can I make that command.


 
You'd probably be better off using document.formname.fieldname.value

fieldname.value will probably work in IE (I'm not really sure), but I don't think it will in Netscape.

If I'm understanding you correctly, here's a quick example of what you want to do. Just enter something in the first text field, click the button, and it will show up in the second one.
Code:
<html>
<head>
<script>
function dothis() {
document.forms[0].taker.value = document.forms[0].name.value
}
</script>
</head>
<body>
<form>
<input type=&quot;text&quot; name=&quot;name&quot; />
<br />
<input type=&quot;button&quot; onclick=&quot;dothis()&quot; value=&quot;Update&quot; />
<br />
<input type=&quot;text&quot; name=&quot;taker&quot; />
</form>
</body>
</html>
 
Excellent code aperfectcircle. Next question. Without trying to use cookies, do you know of a way for the same thing to happen except i want the text to come up on a textbox on a differnt webpage?

by the way,
you are a genuis
 
by the way, can you explain the code to me that you sent. <script>
function dothis() {
document.forms[0].taker.value = document.forms[0].name.value
}
</script>
</head>
<body>
<form>
<input type=&quot;text&quot; name=&quot;name&quot; />
<br />
<input type=&quot;button&quot; onclick=&quot;dothis()&quot; value=&quot;Update&quot; />
<br />
<input type=&quot;text&quot; name=&quot;taker&quot; />
</form>
 
It is possible to pass variables to another page without using cookies, but it is a LOT more difficult (IMO). I think a cookie that expired when the browser closed would probably work alright something like this. I guess the only problem would be if one user took the exam and then another user used the same computer to take it without closing the browser window...

About the code... Inside the script tags is a simple function called dothis. All it does is set the second text box to have the value the first one did. This function is called when the button is clicked with the onclick event.
If you're wondering about the forms[0] thing, all that means is the first form on the page. If I would've given the form a name like &quot;exam&quot; then I would refer to the text box values as document.exam.taker.value and document.exam.name.value.

Hope this helped clear things up. If not, let me know...

By the way, I am definitely not a genius. I have to remind myself to breathe every now and then...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top