SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast nickweavers's Avatar
    Join Date
    Feb 2004
    Location
    Hampshire, UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can i use a variable for a form name?

    I have a numer of forms that are repeated for information taken from a db.

    PHP Code:
    <form action="index.php" method="get" 
             name="<?php echo $this->form_name;?>">
      <input type="hidden" name="Itemid" value="<?php echo $Itemid?>" />
      <input type="hidden" name="option" value="<?php echo $option?>" />
      <input type="hidden" name="tombola_id" value="" />
      <input type="hidden" name="task" value="" />
    Buy <?php echo mosHTML::integerSelectList0$this->remaining_tickets1'number_of_tickets''size="1" class="inputbox"'0"%02d" ); ?> 
    tickets  
      <input type="image" name="Submit"   src="templates/etombolas/images/enter_tombola.gif"
    border="0" alt="Buy now" title="Buy now"
                                           onclick="ItemTask('<?php echo $form_name;?>','<?php echo $this->id;?>', 'add_to_cart')" />
    </form>
    For each of the form I generate a sequential for name using php. The submit button on each form calls a javascript that sets hidden fields in the form to be passed on to the action page.

    Code:
    		function ItemTask(formName, tombola_id, task) {
    		  thisForm = document.eval(formName);
    		  alert("formName=" + formName);
    			thisForm.tombola_id.value = tombola_id;
    			thisForm.task.value = task;
    			thisForm.submit();
    		}
    I didn't works so I tried using eval in case it was required. Still doesn't seem to work.

    Can any one help?

    TAI.

  2. #2
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    document.forms[formName]
    You can also give each form an ID and access it with document.getElementById

  3. #3
    SitePoint Enthusiast nickweavers's Avatar
    Join Date
    Feb 2004
    Location
    Hampshire, UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great... that did the trick.

    Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •