Submit form with URL parameters

I want to submit a form with URL , by clicking on a link . My page name is "MyPage.php"
Here is what am doing .
echo "<td><a href='MyPage.php?Filter=1' onclick='javascript: submit()' ;>  Search </a></td>";
I cant use hidden field, I cant modify form action attribute> I must have to submit form with concatenating "Filter=1" with page name. that is 'MyPage.php?Filter=1' .
But this line is not submiting my form. Plz help.....
echo "<td><a href='MyPage.php?Filter=1' onclick='javascript: submit()' ;>  Search </a></td>";

Open in new window

Naveed_ManzoorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ritetekCommented:
Could you maybe post a url or a more complete version of the code.  Also, is there an error being output or it just doesn't do anything?
0
LakioCommented:
0
Michel PlungjanIT ExpertCommented:
If the complete url of a form is Mypage.php?Filter=1 and the method of the form is GET then no need for the form at all:
<a href="Mypage.php?Filter=1">Load Mypage.php with filter=1</a>

If you have a form like this

<form action="MyPage.php" method="GET">
<input type="hidden" name="Filter">
</form>

you can do

<a href="#"
onClick="document.forms[0].Filter.value='1';
document.forms[0].submit(); return false">Set filter to 1, submit and do NOT follow this link (since that would reload the page and interfere with the submission)</a>
The above assumes the form is the first ([0]) form on the page

do NOT call any form field
name="submit"
since that will also interfere
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

LakioCommented:
or
<form action="MyPage.php?Filter=1" method="GET" name="theFormInQuestion"></form>
<a href="#" onClick="document.theFormInQuestion.submit(); return false">Send</a>
0
Michel PlungjanIT ExpertCommented:
But that would be completely pointless since


<form action="MyPage.php?Filter=1" method="GET" name="theFormInQuestion"></form>
<a href="#" onClick="document.theFormInQuestion.submit(); return false">Send</a>

is identical to

<a href="MyPage.php?Filter=1">Send</a>
0
LakioCommented:
yes.. hehe but only if there are no other fields
0
Naveed_ManzoorAuthor Commented:
The form method is "POST" not "GET". mplungjan can ur code work with post method .
<a href="#"
onClick="document.forms[0].Filter.value='1';
document.forms[0].submit(); return false">Set filter to 1, submit and do NOT follow this link (since that would reload the page and interfere with the submission)</a>
with out <input type="hidden" name="Filter">. Cant use any hidden field or get method
0
Michel PlungjanIT ExpertCommented:
Why can't you use a hidden field

try this:


<form action="" method="POST">
</form>

<a href="#"
onClick="document.forms[0].action='MyPage.php?Filter.value='1';
document.forms[0].submit(); return false">Submit and do NOT follow this link (since that would reload the page and interfere with the submission)</a>
0
Naveed_ManzoorAuthor Commented:
I have used this
<a href='#' onClick='document.forms[0].action='MyPage.php?Filter.value='1'; document.forms[0].submit(); return false'>Search</a>

The current url of page is http://localhost/proj/MyPage.php?Status=1

And when I click on "search" nothing happened except url changes to
http://localhost/proj/MyPage.php?Status=1# 
(# concatenated.).Neither form submit nor url picked Filter =1

WIll using hidden field help me craeting this URL
http://localhost/proj/MyPage.php?Filter=1
This is all I want that I get Filter=1 in my URL and it also get subit on same time.


0
Michel PlungjanIT ExpertCommented:
That the page changes to # is because the script is wrong
You have a problem with your quotes (and I had a problem with mine before the 1)

<a href='#' onClick='document.forms[0].action='MyPage.php?Filter.value='1'; document.forms[0].submit(); return false'>Search</a>

should be

<a href="#"
onClick="document.forms[0].action='MyPage.php?Filter.value=1';
document.forms[0].submit();
return false">Search</a>


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.