form with two buttons

Hi! I have a form with two input text fields and two buttons like this

[code]



[/code]

What i want to achieve is if i click the button “Roll” it generates two random numbers and writes them in the text fields and if i click “Save” i want them to be saved in a MySQL table.

The problem with this code is that it always goes to “save.php” file but i want it to stay in this form.
One sollution could be editing those text fields using php. Is it possible witout leaving the form?

Yes. When the button gets pressed, you can override it redirecting you to save.php if you add in something like onClick=“return false”

Here are the 2 modifications I made:

 function RollBaseStats()
{
var BaseCombat=Math.floor(Math.random()*10)+10
document.getElementById("text1").value=BaseCombat
var BaseEndurance=Math.floor(Math.random()*10)+20
document.getElementById("text2").value=BaseEndurance;
return false;
}

For your function RollBaseStats, I added “return false” at the end.

<input  name="Roll" style="height:33px"  type="submit" value="Roll" onclick="return RollBaseStats()" /></div>

For your input box, I modified it to “return RollBaseStats().”

What this will do is upon clicking the button, you are telling it to execute RollBaseStats() and return whatever RollBaseStats returns (which happens to be false every time).

Great thanks! I never thought it couls be solved so easy.

anytime ;D ping me if you have more questions

Sponsor our Newsletter | Privacy Policy | Terms of Service