Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a submit button generate msg?

Status
Not open for further replies.

raulgh

Programmer
Aug 20, 2003
20
SG
Dear all:

I just want to know is there a way to make a submit button to generate a msg so that I can pass it to another PHP page to do some processing.

My design is to have a frame on the left which contains several submit buttons. Buttons are placed in a table which is contained in a form. When user clicks the different button, different msg will be passed to anthor frame which is a PHP page.So that the PHP page will react depend on the msg it received. Is it possible to do so with out using JAVA script? Pls give me some highlights. Thanks a lot.
 
Put each submit button in a separate form. Set each form's action attribute to reflect the message you want passed to the server.
 
Hi dwarfthrower:

Thanks a lot for your reply. But I think I might have some alignment problem if I am to put every frame in a table. So maybe I have to resort to JAVAscript's onclick methods, although I really prefer a pure html approach as I am not very familiar with JAVA script :)
 
We can help you with the javascript if you want just one form and a dynamic action= attribute.
eg:
Code:
<script>
function makeTarget(formObject, newTarget)
{
  formObject.action.value=newTarget;
}
</script>
<form method=&quot;post&quot; action=&quot;&quot;>
<input type=&quot;submit&quot; name=&quot;submit1&quot; value=&quot;Submit 1&quot; onclick=&quot;makeTarget(this.form,'target1.asp');&quot;>
<input type=&quot;submit&quot; name=&quot;submit2&quot; value=&quot;Submit 2&quot; onclick=&quot;makeTarget(this.form,'target2.asp');&quot;>
</form>

wrote that on the fly, there might be syntax errors :). You'll have to add in the frame kruft yourself (advice: get it working without them first, then add them)

Second piece of advice: don't use frames at all if this is going to be used by any 'users'. I can point you towards many articles to back this advice up if you want :)

good luck

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Thanks a lot Clarkin. I think it will work. Right now I am using onclick, but dynamic action seems more logical.
 
Hi raulgh,

One method I use is to have several submit buttons with different values. For example:

<form>
<input type=&quot;submit&quot; name=&quot;button&quot; value=&quot;msg1&quot; />
<input type=&quot;submit&quot; name=&quot;button&quot; value=&quot;msg2&quot; />
</form>

Then your server-side code receives button=msg1 or button=msg2, depending on what button was pressed.

Cheers,
petey

News and views of some obscure guy
 
Or, alternatively, give your submit buttons different names:
[tt]
<input type=&quot;submit&quot; name=&quot;button1&quot; value=&quot;Submit&quot; />
<input type=&quot;submit&quot; name=&quot;button2&quot; value=&quot;Submit&quot; />
[/tt]
Your server-side code then checks to see if button1 has a value or button2 does.

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top