PDA

View Full Version : [SOLVED] HTML form button and radiobutton PHP questions



dmillerw
December 4th, 2009, 01:10 AM
What I'm attempting is to have a HTML form submit button that when clicked, creates a javascript dialog box that will allow the user to continue or cancel the action, is this possible?

Secondly, is there a way to have a radio button's default be a value in a MySQL database?

korvirlol
December 4th, 2009, 02:20 AM
What I'm attempting is to have a HTML form submit button that when clicked, creates a javascript dialog box that will allow the user to continue or cancel the action, is this possible?


here is an example:


<script>
function trysubmit(){
var submit = confirm("are you sure you want to continue?");

if(!submit){
return false;
}

document.yourform.submit();
}
</script>

<form action = '' method = '' name = 'yourform'>

form stuff

<input type = 'button' value = '' onclick = 'trysubmit()'>
</form>you can have any form element be whatever value from your database from a query. Note that radiobuttons are either checked, or not checked. You can "check" the radio button when your page loads by using the attribute "checked":


<input type = 'radio' checked>

dmillerw
December 4th, 2009, 04:33 AM
here is an example:


<script>
function trysubmit(){
var submit = confirm("are you sure you want to continue?");

if(!submit){
return false;
}

document.yourform.submit();
}
</script>

<form action = '' method = '' name = 'yourform'>

form stuff

<input type = 'button' value = '' onclick = 'trysubmit()'>
</form>you can have any form element be whatever value from your database from a query. Note that radiobuttons are either checked, or not checked. You can "check" the radio button when your page loads by using the attribute "checked":


<input type = 'radio' checked>
I tried that code, but it executes the form whether I press OK or Cancel

dmillerw
December 4th, 2009, 07:46 AM
Anyone

CyberJack
December 4th, 2009, 02:30 PM
This sould work for the submitting part.
Now if javascript is disabled your form will still be submitted. This means that you have to check your input of the processing side (always highly advisable).



<html>
<head>
<script type="text/javascript">
function trysubmit()
{
var submit = confirm("are you sure you want to continue?");
if(!submit)
return false;
return true;
}
</script>
<head>
</body>
<form action='' method='' name='yourform' onsubmit="return trysubmit();">
<input type='submit'>
</form>
</body>
</html>


The automatically checking of a radiobutton depends on you html style.(so does the code above).
If you use html 4.01 you can you the example from korvirlol.
If you use xhtml use this code:



<input type="radio" value="" name="" checked="checked" />

korvirlol
December 5th, 2009, 05:44 AM
Anyone

The very simply example I posted works.

perhaps you should post the code you used. It would be more beneficial then simply posting it doesnt work.

dmillerw
December 5th, 2009, 06:25 AM
My bad, but CyberJacks code worked, thanks.