Categorized | JavaScript, Tutorial

JavaScript – Agree Before Entry -Source Code

Save this code as external JavaScript file named: agree.js

var agree=0;

// 0 = ‘no’, 1 = ‘yes’

function agree2() {
if (!document.getElementById) return false;
agree=1;
document.getElementById(‘box’).style.background=’#fff000′;
if (agree) {
document.getElementById(‘enterName’).style.visibility = ‘visible’;
}
document.enableform.box.focus();
}

function disagree() {
if (!document.getElementById) return false;
agree=0;
if (!agree) {
document.getElementById(‘enterName’).style.visibility = ‘hidden’;
}
document.enableform.done.focus();
}

function goSubmit() {
if (agree==0) {
alert(“DISGREE: You can insert the next step here”);
} else if (agree==1 && document.enableform.box.value==”) {
alert(“You must enter your name!”);
document.enableform.box.focus();
} else {
alert(“AGREE: You can insert the next step here”);
}
}

Save this code in the <style> section within the HEAD section of HTML document.

#enterName {
visibility: hidden;
padding-left: 50px;
}

Save this code into the HEAD section of HTML document
<script type=”text/javascript” src=”agree.js”></script>

Save this code into the BODY section of HTML document

<form name=”enableform”>
<input type=”radio” name=”enable” value=”agree” onclick=”agree2();”>I agree
<div id=”enterName”>Please enter your name to show agreement: <input type=text id=”box” name=”box”></div>
<input type=”radio” name=”enable” value=”disagree” onclick=”disagree();”>I disagree
<br><br>
<input type=”button” value=”Done!” name=”done” onclick=”goSubmit()”>
</form>

Related posts:

  1. Accessing the form elements                  The form validation script needs to access the form in the HTML page to determine what values the user...
  2. Free-Code-JavaScript JavaScript – Increament function Script JavaScript – E-mail Validation Script...
  3. JavaScript – Increament function <HTML><HEAD><TITLE>ABC</TITLE> <SCRIPT LANGUAGE=”JAVASCRIPT” TYPE=”TEXT/JAVASCRIPT”> <!– a = 23; function ad() { a = (++a); alert(a); } //–> </script> </HEAD> <BODY>...
  4. JavaScript – Email Validation script var emailfilter=/^w+[+.w-]*@([w-]+.)*w+[w-]*.([a-z]{2,4}|d+)$/i function checkmail(e){ var returnval=emailfilter.test(e.value) if (returnval==false){ alert(“Please enter a valid email address.”) e.select() } return returnval }...
  5. ASP-JavaScript In this tutorial we will create a regular HTML page with a small javascript code, and we will use this...

Leave a Reply

*

Page Rank

Skype Online Status

Call me! - Shashidhar Kumar: My status is Offline