Very simple javascript problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Hughes

    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_oncl ick(templateid)
    {
    // the templateid 8
    // needs to get the value of the form element template8

    alert( What goes here!!!);
    }

    Thanks

    Chris Hughes


  • DB McGee

    #2
    Re: Very simple javascript problem

    "Chris Hughes" <chris_hughes4N OSPAM@hotmail.c om> wrote in message
    news:3f96b282$0 $109$65c69314@m ercury.nildram. net...[color=blue]
    > I have a function that is passed a id number called templateid. The value[/color]
    is[color=blue]
    > 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_oncl ick(templateid)
    > {
    > // the templateid 8
    > // needs to get the value of the form element template8
    >
    > alert( What goes here!!!);
    > }
    >[/color]

    Something like this?

    function createpage_oncl ick( templateid ) {
    elementId = "template" + templateid;
    oFormElement = document.getEle mentById( elementId );
    // Alert the value
    alert( oFormElement.va lue );
    }


    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?


    Comment

    • Richard Cornford

      #3
      Re: Very simple javascript problem

      "Chris Hughes" <chris_hughes4N OSPAM@hotmail.c om> wrote in message
      news:3f96b282$0 $109$65c69314@m ercury.nildram. net...[color=blue]
      >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.template 8.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_oncl ick(templateid)
      >{
      >// the templateid 8
      >// needs to get the value of the form element template8
      >
      >alert( What goes here!!!);
      >}[/color]

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

      Richard.


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Very simple javascript problem

        "Chris Hughes" <chris_hughes4N OSPAM@hotmail.c om> writes:
        [color=blue]
        > 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[/color]

        document.forms['form1'].elements['template'+temp lateid].value

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        Working...