Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing variables to a form using onclick
    primarykey
    data
    text
    <p>I'm new to javascript and am trying to start somewhat simple. Is it possible to create a function that contains a form object that can be populated by an onclick event?</p> <p>Right now I have a page with 7 buttons, each button is a submit for a separate form, they all link to the same php file on the backside of my site where they are processed. I would like to somehow create one single form, possibly in a javascript function, that would accept variables from the buttons when clicked and then submit the form to my php script. it will technically function the same as it does now with 7 different forms, one for each button, but will hopefully cut back on the code.</p> <p>This example is only how I logically thought it might work from a couple of weeks searching around the internet and gathering bits from here and there, but in reality it is far from functional.</p> <p>example:</p> <pre><code>&lt;script type="text/javascript"&gt; function form_variables(opt1,opt2,opt3){ &lt;form name='mySelectionForm' action='form.php?action=form_action' method='post' enctype='multipart/form-data'&gt; &lt;input type='hidden' name='number' value='" + opt1 + "' /&gt; &lt;input type='hidden' name='id' value='" + opt2 + "' /&gt; &lt;input type='hidden' name='option' value='" + opt3 + "' id='options' /&gt; &lt;/form&gt;; formObject.submit(); } </code></pre> <p>Then this would be populated by an onclick event like this.</p> <pre><code>&lt;a href="javascript: void(0);" onclick="form_variables('9','1','6');" title="submit_button1" value="Button 1" class="cssButton"&gt;My Selection&lt;/a&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload