Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
566 views
in Q2A Core by
I am trying to build a COMBINED Ask-Search Input area. So one input field or textarea with 2 buttons, one for search and one for asking.

I found several turorials based on javascript but no one deals with the methods.

The problem is that the original ASK form uses method POST and the original SEARCH form uses method GET.

Can I some how change the method of one of both or is there any other known way how to deal with that ?
Q2A version: 1.5

1 Answer

0 votes
by

Ok, found a solution through java.

Hope it is usefull for somebody.

Having two input buttons in the same form (myform) it works by adding that javascript to the theme:

 

<script type="text/javascript">
function OnSubmitForm()
{
  if(document.pressed == "Ask")
  {
   document.myform.action ="/ask";
   document.myform.method ="post";
   document.myform.title.name ="title";
  }
  else
  if(document.pressed == "Search")
  {
    document.myform.action ="./search";
   document.myform.method ="get";
   document.myform.title.name ="q";
  }
  return true;
}
</script>
 
and as form:
 
<FORM name="myform" onsubmit="return OnSubmitForm();" method="">
<textarea id="title" NAME="q" rows="2" CLASS="qa-main-my-field" onfocus="this.value=\'\'; this.style.color=\'#000000\'; this.onfocus=null;" >... ask Your question ...</textarea>
<INPUT CLASS="qa-main-my-button" NAME="doask1" title="" onclick="document.pressed=this.value" value="Ask" TYPE="submit">
<INPUT CLASS="qa-main-my-button" NAME="" title="" onclick="document.pressed=this.value" value="Search" TYPE="submit">
</FORM>
 
It works so far, but could be optimized.
 
Better would be an aproach where both buttons always send to the same action lets say ./search, and then on severside adding something to the script to redirect in case the ask button was clicked to the ask site. This would avoid the use of the extra java script. If anyone figures that out, please let me know.

 

...