close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Clear textbox if checkbox unticked

Thread began 5/21/2018 9:45 am by warpsys | Last modified 6/12/2018 6:53 pm by Ray Borduin | 96 views | 26 replies |

warpsys

Clear textbox if checkbox unticked

I have a form that needs to be submitted and, if a checkbox is ticked an email textbox will appear where the visitor can enter their email address. If they change their mind an untick the checkbox, how can I get that untick action to empty the email text box?

The users have to agree to the website terms but the email address is only inserted into the database if they tick the email checkbox above. This works fine, but if they don't tick the box, I still need them to be taken to the next page. How can I achieve that please

Sign in to reply to this post

Ray BorduinWebAssist

You can do it server-side in php.

Just add a value attribute to your checkbox like value="1".

Then add code like this to the top of the page that processes the form:

php:
<?php

if (!isset($_POST['c1'])) {
  
$_POST['Email_Address'] = "";
}
?>
Sign in to reply to this post

warpsys

Thanks Ray - that worked although it still puts a NULL value in the database if it is unticked. Is there a way to get to the next page without putting a value in if the checkbox is unticked?

Also, is there a way to clear the email textbox if there is a value in there initially and then the user changes their mind and unticks the box. At the moment the value stays in there and is still inserted into the database even if they later untick the email check box?

Many thanks

Sign in to reply to this post

Ray BorduinWebAssist

Please attach a copy of the php page where the database is updated. I'll need to look at that to see what might be wrong with it.

Sign in to reply to this post

warpsys

Thanks please see attached

Sign in to reply to this post

Ray BorduinWebAssist

I don't see the code I told you to add on this page at all. It should be near the top somewhere above line 21.

Sign in to reply to this post

warpsys

Hi Ray

It's on line 170

....I have just moved it up

Sign in to reply to this post

Ray BorduinWebAssist

It has to be above the code that inserts into the database that starts on line 21 or it won't work.

Sign in to reply to this post

warpsys

I have just moved it up but still the same?

Sign in to reply to this post

Ray BorduinWebAssist

You mean the email address is still stored in the database when the checkbox is unchecked? I don't see how that would be possible with the code in place. Are you sure it was uploaded? I'd need FTP access to debug further, but it really appears that code would work.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...