Click to See Complete Forum and Search --> : [RESOLVED] conditional submit button???


MMWizard
05-22-2006, 11:06 AM
Hello,

I'm creating a subscription form and i like to know how to create an interactive submit button.

What i want is a submit button which only can be used when they agree with the terms of conditions by checking a checkbox. Can u please tell me how i can do that???

Thanx in advance and greetz.. :)

Gilbert

Houdini
05-22-2006, 11:12 AM
You would need to use JavaScript

bogu
05-22-2006, 12:26 PM
This is the topic where u should post your question:
ClientSide Technologies (http://phpbuilder.com/board/forumdisplay.php?f=27)
Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

About the question:

There is disable <-- javascript event ...

MMWizard
05-22-2006, 12:38 PM
Ohw, i'm sorry.
Im new(in coding PHP) and here at this forum and hoped there was something like this in php.
But i will look at the other topic to get some more result about the disable JAVASCRIPT EVENT. But thanx a lot for giving me some direction. I thought this would be the simplest part of my PHP form but never is ever like it seems...

bogu
05-22-2006, 04:10 PM
Look here I made u and example of what u need:

<form>
<input type="checkbox" name="chk" value="1" onclick="return _DoSomething(this);" />
<input type="submit" name="btn" value="Bimbo :)" disabled />
</form>
<script>
var _dd = document.forms[0];
function _DoSomething(the_chk) {
if (the_chk.checked) {
_dd.btn.disabled = false;
} else {
_dd.btn.disabled = true;
}
}
</script>

Have fun coding. :D

MMWizard
05-23-2006, 03:53 AM
hahaha... thank u very much. It works fine... Now i only have 2 figure out how it works so i can alter and use in other projects... Thank u

greetz Bimbo :)

bogu
05-23-2006, 04:01 AM
greetz Bimbo :)
:p

cretam
06-20-2007, 11:05 AM
Look here I made u and example of what u need:

<form>
<input type="checkbox" name="chk" value="1" onclick="return _DoSomething(this);" />
<input type="submit" name="btn" value="Bimbo :)" disabled />
</form>
<script>
var _dd = document.forms[0];
function _DoSomething(the_chk) {
if (the_chk.checked) {
_dd.btn.disabled = false;
} else {
_dd.btn.disabled = true;
}
}
</script>

Have fun coding. :D

I am so grateful you showed us an example - wasn't sure where to look. For some reason when I tick the box to accespt the terms my button doesn't display.
I have done the same as your example.
<p><input type="checkbox" name="chk" value="1" onclick="return _DoSomething(this);" />Check to accept agreement. <a href="terms.php" target="_blank">View end user licence agreement</a></p>

<p> <input type="submit" name="btn" value="Sign Up!" disabled /></p></form>


I used the script in the header.

Any ideas why it's not working?

bradgrafelman
06-20-2007, 01:49 PM
I don't see any <form></form> tags in your HTML code example... for bogu's code to work properly, the checkbox and submit button must be placed inside a form (the first form on the page, in fact).

EDIT: Correction, I see an ending </form> tag, but no beginning <form> tag.

cretam
06-20-2007, 07:00 PM
I haven't included them because i didn't want to include the entire form but yes they are in form tags.
Here is the form:
<table border="0" cellspacing="0" cellpadding="0" width="450">
<tr>
<td class="pageName">Register as an Individual <p>&nbsp;</p></td>
</tr>
<tr><?php
include("Connections/conn.php");

$regions = @mysql_query('SELECT id, name FROM region ORDER BY name ASC');
if (!$regions) {
exit('<p>Unable to obtain region list from the database.</p>');
}

?>
<td class="bodyText"><form action="login.php?do=new" method="post">

<?php
if (isset($message_new))
echo "<tr><td colspan='2'><b>$message_new</b></td></tr>";
?>* Indicates required field.
<fieldset>
<legend>Personal Information</legend>
<p> <label for="newname">*Username</label>
<input type="text" name="newname"
value="<?php echo @$newname ?>"
size="20" maxlength="20"></p>
<p> <label for="newpass">*Password</label>
<input type="password" name="newpass"
value="<?php echo @$newpass ?>"
size="10" maxlength="8"><br>Use only letters and numbers. Must be between 4 and 20 characters long.</p>
<p> <label for="newpass1">*Confirm Password</label>
<input type="password" name="newpass1"
value="<?php echo @$newpass1 ?>"
size="10" maxlength="8"></p>
<p><label for="firstName">*First Name</label>
<input type="text" name="firstName"
value="<?php echo @$firstName ?>"
size="40" maxlength="40"></p>
<p><label for="lastName">*Last Name</label>
<input type="text" name="lastName"
value="<?php echo @$lastName ?>"
size="40" maxlength="40"></p>
<p><label for="dob">*Date of Birth</label>
<input type="text" name="dob" id="demo1"
value="<?php echo @$dob ?>"
size="10" maxlength="10"> <a href="javascript:NewCal('demo1','ddmmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></p>
<p><label for="email">*Email Address</label>
<input type="text" name="email" value="<?php echo @$email ?>"
size="40" maxlength="40"></p>
<p><label for="driverlicence">Drivers Licence</label>
<input type="text" name="driverlicence" value="<?php echo @$driverlicence ?>"
size="20" maxlength="20"></p>
<p><label for="phone">*Phone</label>
<input type="text" name="phone" value="<?php echo @$phone ?>"
size="15" maxlength="20"></p>
<p><label for="fax">Fax</label>
<input type="text" name="fax" value="<?php echo @$fax ?>"
size="15" maxsize="20"></p>
<p><label for="mobile">Mobile</label>
<input type="text" name="mobile" value="<?php echo @$mobile ?>"
size="15" maxlength="15"></p>
</fieldset>
<fieldset><legend>Address Details</legend>
<p><label for="street">*Street</label>
<input type="text" name="street" value="<?php echo @$street ?>"
size="40" maxlength="40"></p>
<p><label for="city">*City</label>
<input type="text" name="city" value="<?php echo @$city ?>"
size="40" maxlength="40"></p>
<p><label for="state">*State</label>
<input type="text" name="state" value="<?php echo @$state ?>"
size="4" maxlength="4"></p>
<p><label for="postcode">*Postcode</label>
<input type="text" name="zip" value="<?php echo @$zip ?>"
size="4" maxsize="4"></p>


<p><strong>*Select regions you are willing to work in:</strong></br></br><?php

while ($region = mysql_fetch_array($regions)) {

$rid = $region['id'];

$rname = htmlspecialchars($region['name']);

echo "<input type='checkbox' name='regions[]' value='$rid' />$rname </p>\n";
}



?>


</fieldset>
<p><strong>To verify your registration please answer the following question:</strong>
There are 3 colours on the aboriginal flag; black, yellow and ...?</br>(Type the other colour on the flag in the box below.) </p>
<p><input type="text" name="logic" value="<?php echo @$logic ?>" /></p>
<p><input type="checkbox" name="chk" value="1" onclick="return _DoSomething(this);" />Check to accept agreement. <a href="terms.php" target="_blank">View end user licence agreement</a></p>

<p> <input type="submit" name="btn" value="Sign Up!" disabled /></p>

</form></td>
</tr>
</table>

bradgrafelman
07-02-2007, 05:01 PM
Okay.. and where do you define the _DoSomething JS function in your code?