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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button and IE

Status
Not open for further replies.

stasJohn

Programmer
May 6, 2004
155
US
I hope someone can help explain this behavior to me.

I have a form, two buttons...

<button type="submit" name="submit" value="next">next</button>
<button type="submit" name="submit" value="cancel">cancel</button>


When the form is submitted, IE always returns the value "cancel" regardless of which button was pressed.

I thought I could name them the same and it would work. In fact this does work in all other browsers (mozilla, netscape, opera).

If I give the buttons seperate names, then it works. Does IE not interpret the <Button> element the same as it interprets <Input type="submit">???

Thanks in advance.
 
Why would you want to give both buttons the same name when they perform two different tasks?

Anyway, by giving the two buttons the same name, the latter instance over-rides the former - if you switched them round, you'd find that, whichever you pressed, you'd always get the value "next" returned.

Do the easy thing - change the names.
 
giving them the same names makes it easier to check which one was pressed.

For instance in php i just use if( isset($_POST['submit']) )
to determine if the form was submitted or first time on the page. Then I check the value of the button clicked to perform the appropriate action. Makes the coding cleaner. Thats just a preference I guess.


Then why, if you use <input type="submit">, IE has no problem with naming them the same name? I'm probably just missing some fundamental html knowledge here.
 
You're naming two objects the same thing. You'll need to reference them as an array...

Something like:

[tt]$_POST['submit'][0] and $_POST['submit'][1][/tt]

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top