0

I am not very familiar with javascript and I need a help here. I want to submit a form using JavaScript. Here is a code:

<script type="text/javascript">
function submitform()
{
    document.forms["myform"].submit();
}
</script>

<form name="myform" action="index.php?id=search">
    <div class="searchleft"><?php  echo $search['search']; ?>:</div>
    <div class="searchbox"><input type="text" name="query" id="searchbox"></div>
    <div class="searchbtn"><input name="search" onClick="submitform()" type="button"></div>
</form>

I want link after pressing a button to look like: http://127.0.0.1/index.php?id=search&query=blabla, but unfortunately it looks: http://127.0.0.1/index.php?query=blabla What do I have to change to make it look as I want?

3 Answers 3

6

Use a hidden field:

<form name="myform" action="index.php?id=search">
    <input type="hidden" name="id" value="search" />
    <div class="searchleft"><?php  echo $search['search']; ?>:</div>
    <div class="searchbox"><input type="text" name="query" id="searchbox"></div>
    <div class="searchbtn"><input name="search" onClick="submitform()" type="button"></div>
</form>
Sign up to request clarification or add additional context in comments.

Comments

0

There is only the one input on the form when it's submitted. I'm not familiar with php, but if you put search in a hidden field, it will come through on the post.

Comments

0

First of all you must define your method, either "GET" or "POST", in this case, if you don't want url variables you should use POST.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.