Two submit buttons having each parameter

[code]


[/code] I can go either a.php?myText=hello or b.php?myText=hello with the code above.

The code below doesn’t work correctly, but it will show what I want.

[code]


[/code]want-to-be result

If I click the button “a_submit”, it will go to c.php?a=1&myText=hello or c.php?myText=hello&a=1
If I click the button “b_submit”, it will go to c.php?b=1&myText=hello or c.php?myText=hello&b=1

How can I make the above possible (two submit buttons with each parameter in GET value)?

Since you are using JavaScript anyway (even though you have it jumbled with the HTML instead of keeping it separate) you can use hidden fields for the second value. Simply set up hidden fields named ‘a’ and ‘b’ and set their values to “” to start with then set the one you want to pass the 1 to a value of 1 in the JavaScript before submitting the form.

How can I set the one I want to pass the 1 to a value of 1 in the JavaScript before submitting the form?

The following is the code what I made after I read your suggestion.

[code]




[/code]However, there is no difference between "a_submit" and "b_submit". Both produce "c.php?a=1&myText=hello&b=1".

I want that
“c.php?a=1&myText=hello” for “a_submit”
and
“c.php?b=1&myText=hello” for “b_submit”

I said to set the hidden fields to value=“” and update the value of one of them to 1 in the JavaScript.

You also left the JavaScript jumbled with the HTML where it is far more difficult to update.

[code]

[/code]The code above is the best so far in my ability. I am afraid to say the bellow Would you show me the javascript code which can be updated easily instead of my jumbled one?

I just thought of a better way than setting the value - disabling the hidden field you don’t want sent. Try this:

<form method="get" action="c.php">
<input type="submit" id="as" value="a_submit">
<input type="hidden" value="1" name="a" id="a">
<input type="hidden" value="1" name="b" id="b">
<input type="text" value="hello" name="myText">
<input type="submit" id="bs" value="b_submit">
</form>
<script>
document.getElementById('as').onclick = function() {
   document.getElementById('b').disabled= true;;
};
document.getElementById('bs').onclick = function() {
   document.getElementById('a').disabled = true;
};
</script>

Click the a_submit should now produce -
c.php?a=1&myText=hello

Click the b_submit should now produce -
c.php?b=1&myText=hello

In each case the disabled hidden form field should not get sent.

Thank you, felgall, it works.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.