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

display text box value 2

Status
Not open for further replies.

skibascott

IS-IT--Management
Mar 18, 2004
82
US
I have some hidden text boxes that are populated with text using javascript. Can I format and display the text within them without using the text box? If so, how do I reference the text in my html?

ex.
Code:
<input type="hidden" name="Tool">

<h1>I would like the text from the "Tool" text box to go here</h1>
 
hidden fields are not text boxes... you can get a value from them:

<input type="hideen" name="toolbox" value="12345">

document.form.toolbox.value

[conehead]
 
Like this?

Code:
<script language="javascript">
<!--
  document.write("<h1>" + document.forms['formname'].elements['Tool'].value + "</h1>");
-->
</script>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
I understand that much, now how do I reference that value in my html? Do I need to output the html tags with the document.write method, or can I keep the html the way it is and insert the javascript value with special tags?
 
Display it in div tags using innerHTML. Here's an example:
Code:
<html>
<head>
<script language=javascript>

function saveFunction(str) {
   blahForm.blahHidden.value = str;
   blahForm.blahText.value = '';
}

function displayFunction(str) {
   document.getElementById("blahDiv").innerHTML = str;
}

</script>
</head>
<body>
<form name=blahForm>
<input type=hidden name=blahHidden>
<input type=text name=blahText><br>
<input type=button value='save to hidden variable' onclick='saveFunction(blahForm.blahText.value)'><br>
<input type=button value='display hidden variable' onclick='displayFunction(blahForm.blahHidden.value)'>
<div id=blahDiv></div>
</form>
</body>
</html>

-kaht

banghead.gif
 
Another way:

Code:
<h1>
<script language="javascript">
<!--
  document.write(document.forms['formname'].elements['Tool'].value);
-->
</script>
</h1>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Thank you cLFlaVA. That answered my question. I was in the process of replying, apparently after you posted.
 
I am also a big fan of the innerHTML manipulation, however it will not work in some older browsers.

If you'll be doing this in more than one place, I do suggest creating a function as kaht has displayed.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top