471,073 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Very simple javascript problem

I have a function that is passed a id number called templateid. The value is
an identifer of a form element.
To get the value I want I would use the following

form1.template8.value

In the function I need to get the templateid (which is 8) and get it to
display the value of template8 etc

How do i do this??

function createpage_onclick(templateid)
{
// the templateid 8
// needs to get the value of the form element template8

alert( What goes here!!!);
}

Thanks

Chris Hughes
Jul 20 '05 #1
3 1622
"Chris Hughes" <ch*****************@hotmail.com> wrote in message
news:3f*********************@mercury.nildram.net.. .
I have a function that is passed a id number called templateid. The value is an identifer of a form element.
To get the value I want I would use the following

form1.template8.value

In the function I need to get the templateid (which is 8) and get it to
display the value of template8 etc

How do i do this??

function createpage_onclick(templateid)
{
// the templateid 8
// needs to get the value of the form element template8

alert( What goes here!!!);
}


Something like this?

function createpage_onclick( templateid ) {
elementId = "template" + templateid;
oFormElement = document.getElementById( elementId );
// Alert the value
alert( oFormElement.value );
}
Also, I'm curious as to what context you are calling this function in - eg.
where do you get the 'templateid' from when you call the function?
Jul 20 '05 #2
"Chris Hughes" <ch*****************@hotmail.com> wrote in message
news:3f*********************@mercury.nildram.net.. .
I have a function that is passed a id number called templateid.
The value is an identifer of a form element.
To get the value I want I would use the following

form1.template8.value

In the function I need to get the templateid (which is 8) and
get it to display the value of template8 etc

How do i do this??

function createpage_onclick(templateid)
{
// the templateid 8
// needs to get the value of the form element template8

alert( What goes here!!!);
}


<URL: http://www.jibbering.com/faq/#FAQ4_39 >

Richard.
Jul 20 '05 #3
"Chris Hughes" <ch*****************@hotmail.com> writes:
I have a function that is passed a id number called templateid. The value is
an identifer of a form element.
To get the value I want I would use the following

form1.template8.value

In the function I need to get the templateid (which is 8) and get it to
display the value of template8 etc


document.forms['form1'].elements['template'+templateid].value

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Keiron Waites | last post: by
reply views Thread by 42 | last post: by
27 posts views Thread by one man army | last post: by
4 posts views Thread by Chris Zopers | last post: by
112 posts views Thread by Prisoner at War | last post: by
18 posts views Thread by Daniel Orner | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.