Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get a JS var inserted into a hidden field
    primarykey
    data
    text
    <p>I promise...I have researched this for over 24 hours. I know it is similar (if not exactly the same) as some other questions. I'm obviously missing something. (This is going to be a long-winded explanation...I apologize. Please don't let it scare you off...I'm pretty sure the root problem/question will be much easier than what all this looks like!)</p> <p>End result desired is to get some JS vars POSTed over to my process PHP script from an HTML form. Simple, right?</p> <p>I have a fully working form that does a bunch of calculations with a <em>bunch</em> of input fields...it's way too complex to post here...not to mention I really don't want to embarrass myself with what I'm sure is very bad coding!</p> <p>In a nutshell...I have a function that in the process of running sets various JS vars. I need to get these vars inserted into some hidden input fields so that they will get moved over to my processing PHP along with all of the "normal" inputs. All of these vars represent floating point numbers (if that makes any diff)</p> <p>Here is my form definition:</p> <pre><code>&lt;form id="multiForm" action="App_post.php" method="POST" action="javascript:void(0)" id="appform" name="appform"&gt; </code></pre> <p>I have a "master" function that starts all of the calculations primarily based on when the user selects various radio buttons. Various selectors are dynamically updated in the form as the user selects buttons (which in reality is a user selecting different options of club membership fees and "add-on" items...someone is bound to ask what I'm doing!)</p> <pre><code>$(function () { ...lots of JS code here along with the calculations that create the JS vars I need } </code></pre> <p>(I assume this function is called via the action="javascript:void(0)" )</p> <p>Let's focus on just one var right now. The JS var "regularfee" (along with all the others I want) exists after all of the calculations are done. I need to have these values plugged into the hidden fields so that they can get POSTed.</p> <p>Here is an example of the hidden field:</p> <pre><code>&lt;input type="hidden" name="regularfee" id="regularfee" value=""&gt; </code></pre> <p>Here is where I am getting lost. I have done a console.log(regularfee) in the function right after all the calculations are done...it is set to the float number 26.5 (which is correct)</p> <p>Here are a couple of things I have tried so far:</p> <pre><code>document.getElementById('regularfee').value=regularfee; // --OR-- document.getElementById('regularfee').value=regularfee.value; document.getElementById("app").submit(); </code></pre> <p>No matter what I've tried, I get blank values POSTED over to my process PHP. Based on the other questions I've seen, the hidden input field method <em>appears</em> to be one of the "accepted" ways of doing this. I am not stuck on this method...just looking for the easiest way to get my vars POSTed! What am I missing? All help extremely appreciated!</p>
    singulars
    1. This table or related slice is empty.
    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