Note that there are some explanatory texts on larger screens.

plurals
  1. POheader('Location: ) in php switch to execute url with onclick function
    text
    copied!<p>To put it simply I have this variable which carries a hyperlink:</p> <pre><code>$test3 = '&lt;a href="#" onclick="archiveMove(\''.$mulmov.'\'); return false;"&gt;Move to Quotes&lt;/a&gt;'; </code></pre> <p>and what I need is to execute this variable inside a switch case like below:</p> <pre><code>switch ($_POST['dropdown']) { case "Select Folder": echo "Please select"; break; case "One": exec($test3); &lt;-- //here i want to run (if this is not execute, my misunderstanding) the link. break; case "Two": header('Location: http://www.facebook.com/'); &lt;-- //this is just a test break; default: echo "&lt;br&gt;&lt;/br&gt;"; echo "Move multiple files:"; echo "&lt;br&gt;&lt;/br&gt;"; } ?&gt; &lt;form method="post" name="theform" action=""&gt; &lt;select name="dropdown"&gt; &lt;option value="Move to Folder"&gt;Select&lt;/option&gt; &lt;option value="One"&gt;One&lt;/option&gt; &lt;option value="Two"&gt;Two&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" value="Move"/&gt; &lt;/form&gt; </code></pre> <p>I'd like know how to execute the ahref link without the user clicking it, but simply set this link as a case and when the user submits the form, the selected case actions the hyperlink. </p> <p>Any help appreciated. </p> <hr> <h2><em>MORE DETAIL</em></h2> <p>I understand that javascript and php are both seperate languages and that a better option would be to use Ajax, but my understanding of Ajax is limited. </p> <p>To explain it better, this is what's going on in its entirety: </p> <p><strong>1)</strong> I have a mailbox with a selection of messages.</p> <p><strong>2)</strong> You are able to check these messages and then click a link "Trash Selected" which deletes the selected messages. This the link:</p> <pre><code>&lt;a href="#" onclick="deleteInbox(\''.$muldel.'\'); return false;"&gt;Trash Selected&lt;/a&gt; </code></pre> <p>The javascript function actions the php function in $muldel for all selected messages and updates the database.</p> <p>This is the javascript function in question:</p> <pre><code>function inboxDelete(url) { document.messages.action = url; document.messages.submit(); } </code></pre> <p><strong>archiveMove()</strong> is exactly the same, just duplicated temporarily to make things clear.</p> <p><strong>3)</strong> I have now re-used the ahref code to do the same procedure, but this time, for moving the selected messages into folders. </p> <p><strong>4)</strong> These folders can be selected from a drop down box - this is where the form comes in.</p> <p><strong>5)</strong> So although I can get it to work by adding a link like such:</p> <pre><code> $test3 = '&lt;a href="#" onclick="archiveMove(\''.$mulmov.'\'); return false;"&gt;Move to Quotes&lt;/a&gt;'; echo $test3; </code></pre> <p><strong>6)</strong> I now need this to work the same way but the link being changed, depending on which folder is selected. </p> <p>That's the full extent to my problem, I hope this is more clear.</p> <p>I am aware you can send variables into javscript using GET or POST and then carry out the function entirely through javascript. I have tried something like below, but to no avail:</p> <pre><code>&lt;form method=post name="myform" action="&lt;?php echo $PHP_SELF;?&gt;"&gt; &lt;input type="hidden" name="formVar" value=""&gt; &lt;input type="text" value="Enter Text Here" name="myText"&gt; &lt;input type="text" value="Enter Text Here" name="myText2"&gt; &lt;input type="submit" value="Send form!" onClick="readmove()"&gt; &lt;/form&gt; &lt;?php // Retrieve the hidden form variable (using PHP). $myvar = $_POST['formVar']; if ($myvar == "$mulmov"){ echo $mulmov; } ?&gt; &lt;script language="JavaScript"&gt; &lt;!-- function setText(){ document.myform.myText.value = document.myform.myText.value.toUpperCase(); } function readmove(){ document.myform.myText.value = "&lt;?php echo $myvar; ?&gt;" ; readmove2(); } function readmove2(){ if (document.myform.myText.value == "$mulmov"){ document.myform.myText2.value = "&lt;?php echo $mulmov; ?&gt;" ; &lt;?php exec ('archiveMove(\''.$mulmov.'\'); return false;'); ?&gt; } else if (document.myform.myText.value == "$mulmov2"){ document.myform.myText2.value = "&lt;?php echo $mulmov2; ?&gt;" ; } } &lt;/script&gt; </code></pre>
 

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