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

submit button in an html form

Status
Not open for further replies.

rudenborg

Programmer
May 18, 2004
19
US
I can not come up with a solution to what should be a very simple problem. I need to have a submit button on a form with the follow criteria:

1. It has to send a name/value pair to the server where I can set both the name and the value. I have a script that acts differently depending on what submit button gets clicked.

2. I have to at worst, be able to put my own text on the button, preferable be able to use an image.

3. It should be compatible with most browsers.

So I tried <input type="submit">. The problem is the value that is sent to the server via the "value" attribute is also what appears on the button. so if I’m trying to send a value like "12-15" to the server, that's also what shows up on the button to the user.

So I tried <input type="image">. The problem here is that the value sent to the server is always the x-y cordinents of the mouse when clicked. I have no way to set the value.

So I tried <button type="submit">. This one just seems to very buggy. IE for MAC would submit the page but wouldn't send the name/value pair so my script wouldn't act correctly. IE 6 on a PC would send the name so the script would work but wouldn't receive the right value. It seems to actually send as a value, whatever is between the <button> tags which in my case is an <image> tag


If anybody can help me with this it would be greatly appreciated! It's driving me crazy!

Thanks,

Jonathan
 
Code:
<img 
  src="myButton.gif" 
  id="myID" 
  onClick="myScript(this,'value') />

Then you have a script, myScript, which recieves "this", which is the image control itself, and "value", a string:

Code:
<script type="text/javascript">
function myScript(xObj,valStr)
{
  var myName = xObj.id;
  var myValue = valStr;
}

Is that what you're looking for?

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Or you can change the value right before you submit it:
Code:
<form method="post" action="newpage.php">
<input type="text" name="value_to_be_sent_with_button">
<input type="submit" name="button" value="Submit and this value will change" onclick="this.value=this.form.elements['value_to_be_set_with_button'].value">
</form>

--Chessbot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top