Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to control form action depending on condition in javascript?
    primarykey
    data
    text
    <p>I am having a form in PHP. I used both <code>onclick</code> and <code>onsubmit</code> to call a javascript function. On <code>onclick</code> i have called the <code>rangeValidator()</code> and <code>onsubmit</code> i have called <code>formValidator()</code>. I am checking the condition and if that is true then it is redirecting to the page which in <code>form action</code>.</p> <p>Code:</p> <pre><code>&lt;form action="javascript:check();" name="frm" id="frm" onsubmit="return formValidator()"&gt; ..... &lt;input type="submit" onclick="return rangeValidator()"&gt; &lt;/form&gt; </code></pre> <p>Javascript function:</p> <pre><code>&lt;script type="text/javascript"&gt; function rangeValidator() { ...... } function formValidator() { var s=confirm("Are you sure about all the filled in details?"); if(s==true) { return true; } else { return false; } } </code></pre> <p>Now what i want is that, On submit it should check above condition, if that condition is true i want to check the other condition &amp; respectively it should redirect to the page depending on true or false i.e. I want to change the action of the form to two of pages depending on value true or false of <code>condition()</code> function.</p> <p>To change the action I have coded as below.</p> <pre><code>function check() { if(confirm('Do you want to see PF share?')) { url='add_sal_success.php'; document.addsalsuccess.action = url; } else { url='add_sal_success_wo.php'; document.addsalsuccess.action = url; } } </code></pre>
    singulars
    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.
    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