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

field value manipulation

Status
Not open for further replies.

richardhowell

Instructor
Oct 31, 2002
75
GB
In html I want to create a hidden field which is a composite of 3 input fields dd, mm and yy. The input value of the hidden field would look like:

value of yy
"/"
value of mm
"/"
value of dd

Looked on various tutorials but can't find an answer.
Anyone help?
 
You'll need to do a little bit of Javascript
something like:
Code:
var txtyy=document.getElementById("yy");
var txtmm=document.getElementById("mm");
var txtdd=document.getElementById("dd");
var hiddenbox=document.getElementById("hiddenbox");

hiddenbox.value = txtyy.value + "/" + txtmm.value + "/" + txtdd.value;
make sure that in your form you specify the ID attribute of the tag to match the name put in the script ie. getElementbyID("yy")





MrBelfry
 
It doesn't like "document" in the var declaration saying document is undefined. Should this be the document(page) name?

Also...
when you say "make sure that in your form you specify the ID attribute of the tag to match the name put in the script ie. getElementbyID("yy")
... when defining the id attribute should the text I enter be "yy" or "getElementbyID("yy")"
(Sorry if I'm displaying my ignorance!)
 
I can help you with the latter, for the first problem my javascript knowledge is just not good enough.

id should be yy, like this:

<input type=&quot;text&quot; id=&quot;yy&quot;/>

because this: document.getElementById(&quot;yy&quot;); actually means:
in the document, look for an element whose id equals to yy.

Sorry, but can't help you with the first problem.
 
Hi Richard

I've provided an example for you here:

Code:
<html>
<head>
<title>Javascript test</title>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function test()
{
var txtyy=document.getElementById(&quot;yy&quot;);
var txtmm=document.getElementById(&quot;mm&quot;);
var txtdd=document.getElementById(&quot;dd&quot;);
var hiddenbox=document.getElementById(&quot;hidden&quot;);
hiddenbox.value = txtyy.value + &quot;/&quot; + txtmm.value + &quot;/&quot; + txtdd.value;
}
</script>
</head>
<body>
<form>
<input type=&quot;text&quot; id=&quot;yy&quot;>
<input type=&quot;text&quot; id=&quot;mm&quot;>
<input type=&quot;text&quot; id=&quot;dd&quot;>
<input type=&quot;text&quot; id=&quot;hidden&quot;>
<input type=&quot;button&quot; value=&quot;test&quot; onClick=&quot;test();&quot;>

</form>


</body>
</html>

I've tested in IE6, NS7, Opera & Mozilla and it works ok for me


MrBelfry
 
Ah! I see now - it's a function called when onClick. Mine will be onSubmit, so I'll give that a go. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top