JavaScript - Form Validation: Disallowing Selection Of 2 Fields In Drop Down List
Hi there,
I need help in form validation! I want this to be validated upon selection of the drop down list (not when it comes to submit button) I have 2 drop down lists: Starting date (June 5th, 6th 7th) Ending date (June 5th, 6th 7th) I want to write a script that would NOT ALLOW one to choose: - Starting date June 6th and Ending date June 5th - Starting date June 7th and Ending date June 6th - Starting date June 7th and Ending date June 5th I appreciate your help Similar TutorialsHi all, I have been struggling on a bit of code for a while now. I need to populate a second drop down list (Region) based upon the selection of the first (County). I have found a piece of code that works on its own and have adapted to suit my needs - see below. However, when I drop it into my main page the javascript is not working. It's because of the formObject but I just don't know enough to resolve this! Furthermore, I need the textboxes the user has already completed in the form to retain their value once the javascript kicks in as the completed form will submit to a database. This piece of code is working well . . . . Code: <?php $link = mysql_connect('myhost', 'myusername', 'mypassword') or die('Could not connect: ' . mysql_error()); mysql_select_db('mydatabase') or die('Could not select database'); if(isset($_GET["County"]) && is_numeric($_GET["County"])) { $County = $_GET["County"]; } if(isset($_GET["Region"]) && is_numeric($_GET["Region"])) { $Region = $_GET["Region"]; } ?> <script language="JavaScript"> function autoSubmit() { var formObject = document.forms['theForm']; formObject.submit(); } </script> <form name="theForm" method="get"> <!-- County SELECTION BASED ON city VALUE --> <?php ?> <select name="County" onChange="autoSubmit();"> <option value=''</option> <?php //POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN city $sql = "SELECT * FROM county_regions"; $counties = mysql_query($sql,$link); while($row = mysql_fetch_array($counties)) { echo ("<option value=\"$row[CountyID]\" " . ($County == $row["CountyID"]? " selected" : "") . ">$row[County]</option>"); } ?> </select> <?php ?> <br><br> <?php if($County!= null && is_numeric($County)) { ?> <select name="Region" onChange="autoSubmit();"> <?php //POPULATE DROP DOWN MENU WITH RegionS FROM A GIVEN city, County $sql = "SELECT * FROM county_regions WHERE CountyID = $County "; $Regions = mysql_query($sql,$link); while($row = mysql_fetch_array($Regions)) { echo ("<option value=\"$row[CountyID]\" " . ($Region == $row["CountyID"]? " selected" : "") . ">$row[Region]</option>"); } ?> </select> <?php } ?> What follows is my form where the javascript is not working - edited quite a bit to save on space! Code: <head> <script language="JavaScript"> function autoSubmit() { var formObject = document.forms['subform']; formObject.submit(); } </script> </head> <form enctype="multipart/form-data" method="post" action="add_attraction01.php" FORM NAME="FormName"> <input type="hidden" name="MAX_FILE_SIZE" value="32768" /> <label for="Business_name">Business Name</label> <input type="text" size="60" STYLE="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 12px; background-color: #72A4D2;" <id="Business_name" name="Business_name" maxlength=60/><font size="1" face="arial" color="red">Required field</font><br /> <label for="StreetAddress">Address</label> <input type="text" size="60" rows="2" id="StreetAddress" name="StreetAddress" maxlength=120/><font size="1" face="arial" color="red">Required field</font><br /> <label for="Town">Town</label> <input type="text" size="25" id="Town" name="Town" maxlength=25/><font size="1" face="arial" color="red">Required field</font><br /> <?php $link = mysql_connect('myhost', 'myusername', 'mypassword') or die('Could not connect: ' . mysql_error()); mysql_select_db('mydatabase') or die('Could not select database'); if(isset($_GET["County"]) && is_numeric($_GET["County"])) { $County = $_GET["County"]; } if(isset($_GET["Region"]) && is_numeric($_GET["Region"])) { $Region = $_GET["Region"]; } ?> <form name = "subform" method="get"> <select name="County" onChange="autoSubmit();"> <option value=''</option> <?php $sql = "SELECT * FROM county_regions"; $counties = mysql_query($sql,$link); while($row = mysql_fetch_array($counties)) { echo ("<option value=\"$row[CountyID]\" " . ($County == $row["CountyID"]? " selected" : "") . ">$row[County]</option>"); } ?> </select> <?php ?> <br><br> <?php if($County!= null && is_numeric($County)) { ?> <select name="Region" onChange="autoSubmit();"> <?php $sql = "SELECT * FROM county_regions WHERE CountyID = $County "; $Regions = mysql_query($sql,$link); while($row = mysql_fetch_array($Regions)) { echo ("<option value=\"$row[CountyID]\" " . ($Region == $row["CountyID"]? " selected" : "") . ">$row[Region]</option>"); } ?> </select> <?php } ?> <input type="text" size="20"id="Tel_No" name="Tel_No" maxlength=20 onkeypress="return isNumberKey(event)"/><font size="1" face="arial" color="red">Required field</font><br /> <br/> <input type="submit" value="Submit your attraction" name="submit" onclick="return BothFieldsIdenticalCaseSensitive();"/> </form> </body> </html> It's probably obvious to you guys!! Thanks in advance for your help. hello, i am more a designer than a developer so i need your help. i want to create a form containing : 1. drop down list of countries (that i managed to create) 2. action on selection (redirect to a link on country selection) 3. post the selected option into a text box below and remeber (if possible) The remeber part is optional . I want a form where user will select country , based on the selection to be redirected to a link and message display , you selected : [textarea]Option[/textarea] can it be done? How can I open a selection from this drop down list in a new window? Code: <html> <!-- Stop Underline script available from http://www.themssforum.com/FontpageProgramming/Hyperlink-underline/ --> <style type="text/css"> a { text-decoration: none;color: #003366; } /*makes the underline disappear for all links*/ a:visited { color: #003366; } a:hover { color: red; text-decoration: underline; } /*underlines links when hovered over */ a:active { color: #003366; } </style> <head> <TITLE>Travel</TITLE> <META name="description" content="Premier online guide to leisurely travel"> <META name="keywords" content="English Lake District"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 6.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <SCRIPT LANGUAGE="JavaScript"> <!-- v=false; //--> </SCRIPT> <SCRIPT LANGUAGE="JavaScript1.1"> <!-- if (typeof(Option)+"" != "undefined") v=true; //--> </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> <!-- Original: webreference.com --> <!-- Web Site: http://webreference.com --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin if(v){a=new Array();aln=0;} function getFormNum (formName) { formNum =-1; for (i=0;i<document.forms.length;i++){ tempForm = document.forms[i]; if (formName == tempForm) { formNum = i; correctForm = tempForm; break; } } return formNum; } function jmp(formName,elementNum) { getFormNum(formName); if (formNum>=0) { with (document.forms[formNum].elements[elementNum]) { i=selectedIndex; if (i>=0) location=options[i].value; } } } function O(txt,url) { a[k]=new Option(txt,url);k++; } function relate(formName,elementNum,j) { if(v) { k=1; if(j==0) { // default category item a=new Array(); O(">",""); } <!-- Alston --> if(j==1) { // 1st category items a=new Array(); O("Local Directory : ->",""); O("South Tynedale Railway","http://www.lakesandcumbria.com/view/travel/index.htm#South Tynedale Railway"); } <!-- Ambleside --> if(j==2) { // 2nd category items a=new Array(); O("Local Directory : ->",""); O("Lakeland Safari Tours","http://www.lakesandcumbria.com/view/travel/p2.htm#Lakeland Safari Tours"); } <!-- Bowness-on-Windermere --> if(j==3) { // 3rd category items a=new Array(); O("Local Directory : ->",""); O("Adaptours","http://www.lakesandcumbria.com/view/travel/p2.htm#Adaptours"); O("Windermere Lake Cruises","http://www.lakesandcumbria.com/view/travel/index.htm#Windermere Lake Cruises"); } <!-- Carlisle --> if(j==4) { // 4th category items a=new Array(); O("Local Directory : ->",""); O("Settle-Carlisle Railway","http://www.lakesandcumbria.com/view/travel/index.htm#Settle-Carlisle Railway"); } <!-- Coniston --> if(j==5) { // 5th category items a=new Array(); O("Local Directory : ->",""); O("Coniston Launch","http://www.lakesandcumbria.com/view/travel/index.htm#Coniston Launch"); O("Steam Yacht Gondola","http://www.lakesandcumbria.com/view/travel/index.htm#Steam Yacht Gondola"); } <!-- Glenridding --> if(j==6) { // 6th category items a=new Array(); O("Local Directory : ->",""); O("Ullswater Steamers","http://www.lakesandcumbria.com/view/travel/index.htm#Ullswater Steamers"); } <!-- Keswick --> if(j==7) { // 7th category items a=new Array(); O("Local Directory : ->",""); O("Keswick launch","http://www.lakesandcumbria.com/view/travel/index.htm#Keswick Launch"); O("Landscape Minibus Tours","http://www.lakesandcumbria.com/view/travel/p2.htm#Landscape Minibus Tours"); } <!-- Lakeside --> if(j==8) { // 8th category items a=new Array(); O("Local Directory : ->",""); O("Lakeside & Haverthwaite Railway","http://www.lakesandcumbria.com/view/travel/index.htm#Lakeside & Haverthwaite Railway"); } <!-- Penrith --> if(j==9) { // 9th category items a=new Array(); O("Local Directory : ->",""); O("Cumbrian Discoveries","http://www.lakesandcumbria.com/view/travel/index.htm#Cumbrian Discoveries"); } <!-- Ravenglass --> if(j==10) { // 10th category items a=new Array(); O("Local Directory : ->",""); O("Ravenglass & Eskdale Railway","http://www.lakesandcumbria.com/view/travel/index.htm#Ravenglass & Eskdale Railway"); } <!-- Windermere --> if(j==11) { // 11th category items a=new Array(); O("Local Directory : ->",""); O("Alistairs of Windermere","http://www.lakesandcumbria.com/view/travel/p2.htm#Alistairs of Windermere"); O("Lakes Supertours","http://www.lakesandcumbria.com/view/travel/p2.htm#Lakes Supertours"); O("Mountain Goat","http://www.lakesandcumbria.com/view/travel/p2.htm#Mountain Goat"); O("Park Tours and Travel","http://www.lakesandcumbria.com/view/travel/p2.htm#Park Tours and Travel"); } aln2=a.length; getFormNum(formName); if (formNum>=0) { formNum = formNum + 1; with (document.forms[formNum].elements[elementNum]) { for (var i=options.length-1;i>0;i--) options[i]=null; for (var i=1;i<aln2;i++) options[i-1]=a[i]; options[0].selected=true; } } } else { jmp(formName,elementNum); } } function FP_preloadImgs() {//v1.0 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array(); for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; } } // End --> </SCRIPT> <meta name="Microsoft Border" content="none"> </head> <body link="#003366" onload="FP_preloadImgs(/*url*/'file:///C:/Documents%20and%20Settings/Mike/My%20Documents/MAI/My%20Webs/L%26C_COM/navigation/utils/about/about_h.jpg', /*url*/'file:///C:/Documents%20and%20Settings/Mike/My%20Documents/MAI/My%20Webs/L%26C_COM/navigation/utils/a-z/a-z_h.jpg', /*url*/'file:///C:/Documents%20and%20Settings/Mike/My%20Documents/MAI/My%20Webs/L%26C_COM/navigation/utils/join/join_h.jpg', /*url*/'file:///C:/Documents%20and%20Settings/Mike/My%20Documents/MAI/My%20Webs/L%26C_COM/navigation/utils/privacy/privacy_h.jpg', /*url*/'file:///C:/Documents%20and%20Settings/Mike/My%20Documents/MAI/My%20Webs/L%26C_COM/navigation/utils/terms/terms_h.jpg', /*url*/'navigation/utils/contact/contact_h.jpg', /*url*/'navigation/utils/copyright/copyright_h.jpg', /*url*/'navigation/utils/sitemap/sitemap_h.jpg', /*url*/'navigation/utils/suggest/suggest_h.jpg')"> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0" width="975"> <tr> <td width="25%" align="center" rowspan="2" valign="top"> </td> <td height="25"> <p align="center"><font face="Comic Sans MS" color="#FF0000"><b>TRAVEL</b></font> </td> <td width="25%" align="center" rowspan="2" valign="top"> <p> </p> <p> </p> <p> </td> </tr> <tr> </center> <td valign="top" align="center"> <table border=0 cellspacing="0" cellpadding="0"> <tr valign=top> <TD align=center bgcolor="#FFFFFF"><form name=f1 method=post action="" onSubmit="return false;"> <select name=m1 onChange="relate(this.form,0,this.selectedIndex); document.f2.m2.focus();" style="background-color: #FFE0C1" size="1"> <option value="/">Location... <option value="/">Alston, <option value="/">Ambleside, <option value="/">Bowness-on-Windermere, <option value="/">Carlisle, <option value="/">Coniston, <option value="/">Glenridding, <option value="/">Keswick, <option value="/">Lakeside, <option value="/">Penrith, <option value="/">Ravenglass, <option value="/">Windermere, </select><br> <br> <br> </form></td> <td align=center valign="top"> </td> <td bgcolor="#FFFFFF" valign="top"><form name=f2 method=post action="" onsubmit="return false;"> <select name="m2" onchange="jmp(this.form,0)" style="background-color: #FFE0C1" size="1"> <option value="/">> <option value="/"> </select></form></td> </tr> </table> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td width="50%" valign="top" align="center"> </td> <td width="50%" valign="top" align="center"> </td> </tr> </center> </table> </div> </td> </tr> </table> </div> <p></p> </body> </html> The Script works in Firefox, BUT not in Internet Explorer. What am I missing? I need Drop Down menu Boxes to appear when User clicks on a certian Menu option. The way it appears now on the website is all the boxes appear. They should stay "hidden" until a User clicks on the drop down menu selection. Thanks! <head> <script type="text/javascript" language="javascript"> function showInfo() { var typeOne = document.getElementById('bmp'); var typeTwo = document.getElementById('junction'); var typeThree = document.getElementById('mile'); if(document.basicform01.Location_Type.value == "BMP to EMP") { typeOne.style.display="inline"; typeTwo.style.display="none"; typeThree.style.display="none"; } else if(document.basicform01.Location_Type.value == "Junction to Junction") { typeOne.style.display="none"; typeTwo.style.display="inline"; typeThree.style.display="none"; } else if(document.basicform01.Location_Type.value == "Milepost") { typeOne.style.display="none"; typeTwo.style.display="none"; typeThree.style.display="inline"; } else { typeOne.style.display="none"; typeTwo.style.display="none"; typeThree.style.display="none"; } } </script> <style>*[style] {outline:none}</style> </head> <body> <fieldset> <dl> <dt><label for="Location_Type">Location Type *</label></dt> <dd><select class="inputselect" name="Location_Type" id="Location_Type" onchange="showInfo()"> <option value="" selected="selected">Select One...</option> <option value="BMP to EMP">BMP to EMP</option> <option value="Junction to Junction">Junction to Junction</option> <option value="Milepost">Milepost</option> </select></dd> <div id="bmp" style="display:none;"> <dt><label for="bmpDetails">BMP</label></dt> <dd><input class="inputtext" type="text" name="bmpDetails" id="bmpDetails" /></dd> <dt><label for="empDetails">EMP</label></dt> <dd><input class="inputtext" type="text" name="empDetails" id="empDetails" /></dd> </div> <div id="junction" style="display:none;"> <dt><label for="fromJunction">From Junction:</label></dt> <dd><input class="inputtext" type="text" name="fromJunction" id="fromJunction" /></dd> <dt><label for="toJunction">To Junction:</label></dt> <dd><input class="inputtext" type="text" name="toJunction" id="toJunction" /></dd> </div> <div id="mile" style="display:none;"> <dt><label for="milepostNum">Milepost</label></dt> <dd><input class="inputtext" type="text" name="milepostNum" id="milepostNum" /></dd> </div> <p> </dl> <p> </fieldset> </body> Hello everyone, I just stumbled across this forum and thought maybe someone here could help me with a few coding alterations. I would like to position the rss feed selection fields on this feed output so I can scroll the feed with the selection fields remaining stationary. Code: <link rel="icon" type="image/png" href="rss_include/feed-icon-red.png"> <style language='text/css'> @import url('rss_include/style.css'); </style> <script language="javascript"> var XMLHttpRequestObject = false; var img = new Image(); img.src = "rss_include/loading.gif"; if ( window.XMLHttpRequest ) XMLHttpRequestObject = new XMLHttpRequest(); else if (window.ActiveXObject) XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); function changeOptions() { LoadFeed(); } function LoadFeed(value, initial) { if ( XMLHttpRequestObject ) { var dsource = "rss_include/ajax.php?loadfeed"; if (value) dsource += "=" + value; else { var val = document.getElementById("rss_feed").value; if ( val == "" ) document.getElementById("rss_feed").selectedIndex += 1; dsource += "=" + document.getElementById("rss_feed").value; } dsource += "&fulltext=" + document.getElementById("showtext").checked; dsource += "&showimages=" + document.getElementById("showimages").checked; XMLHttpRequestObject.open("GET",dsource); XMLHttpRequestObject.onreadystatechange = function() { if ( XMLHttpRequestObject.readyState != 4 ) { document.getElementById("rss_div").innerHTML = "<center><img class=\"loading\" src=\"" + img.src + "\"></center>"; } if ( XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 ) { document.getElementById("rss_div").innerHTML = XMLHttpRequestObject.responseText; } } XMLHttpRequestObject.send(null); } } </script> <?php require_once("rss_include/config.php"); function LoadFile($xml_file) { $xml = null; if ( !file_exists($xml_file) || !($xml = simplexml_load_file($xml_file)) ) { echo '</select>'; echo "Error opening XML feeds file: $xml_file<br>"; return; } return $xml; } function ShowFeedOptions($xml_file) { echo '<select id="rss_feed" onChange="LoadFeed(this.value)" title="GuyWMustang.com RSS Reader">'; $xml = LoadFile($xml_file); if ( $xml == null ) return; $url = array(); foreach($xml->feeds->category as $category) { echo "<option value=\"\">" . $category['name'] . "</option>"; foreach($category->feed as $feed) { if ( $feed['name'] != "" ) { // Add a spacing to the feeds $name = " " . $feed['name']; $url = str_replace("&", "%26", $feed['url']); $url = str_replace("http://", "", htmlspecialchars($url)); echo "<option value=\"$url\">" . $name . "</option>"; } } } echo '</select>'; $options = array(); $rss = $xml->options[0]; if ( strcasecmp($rss['fulltext'],"true") == 0 ) array_push($options, "true"); else array_push($options, "false"); if ( strcasecmp($rss['images'],"true") == 0 ) array_push($options, "true"); else array_push($options, "false"); return $options; } function SetOptions($options) { if ( sizeOf($options) == 2 ) { echo "<script>document.getElementById(\"showtext\").checked = " . $options[0] . ";</script>"; echo "<script>document.getElementById(\"showimages\").checked = " . $options[1] . ";</script>"; } } if ( isset($_GET['links']) ) { $xml = LoadFile($xml_file); if ( $xml == null ) return; // end the link editing return; } ?> <div class="container" id="container_div"> <a name="top"></a> <div class="header_div"> <div style="display:run-in;float:left;"> <font class="graytext">RSS Feed:</font> <?php $options = ShowFeedOptions($feeds_xml); ?> <input type="checkbox" id="showtext" onChange="changeOptions(this)" checked><font class="graytext">Show Full Article Text</font> <input type="checkbox" id="showimages" onChange="changeOptions(this)" checked><font class="graytext">Show Images</font> </div> <?php SetOptions($options); ?> </div> <div class="rss" id="rss_div"> <script>LoadFeed(document.getElementById('rss_feed').value, true);</script> </div> <!-- <p style="padding:0px;margin-right:2px;margin:0px;" align="center"><a class="top" href="#top">Top</a></p> --> </div> <-- CSS BELOW --> Code: body { overflow: auto; font-family: arial; } div.header_div { position: relative; /*background-color: #EFEFEF;*/ width: 100%; overflow: auto; margin: auto; } div.container { /*border: 1px solid black; background-color: #EFEFEF;*/ position: relative; margin: auto; display: block; overflow: auto; /* SPECIFY HEIGHT & WIDTH AS DESIRED */ height: 90%; width: 80%; } div.rss { width: 99%; margin: 2px; background-color: tan; position: relative; /*border: 1px solid black;*/ } img.loading { position: relative; margin-top: 50px; } a.rss_link,a.rss_link:active { display: inline; color: blue; } a.rss_link:hover { color: #BBBBFF; } a.rss_link:visited { color: black; } a.top,a.top:active { text-decoration: none; font-size: 10pt; display: inline; color: black; } a.top:hover { text-decoration: underline; color: brown; display: inline; } font.graytext { font-size: 10pt; color: #444444; } font.rss_title { font-size: 12pt; font-weight: bold; text-decoration: underline; } font.rss_date { font-size: 9pt; font-weight: normal; color: black; display: block; } font.rss_description { font-size: 12pt; color: blue; } select { color: black; font-size: 10pt; background-color: #EAEAEA; } any help would be greatly appreciated.....thanks What I want to do, is that, when the user select one option out of many from the dropdown box some new fields appears. I was so close to make it , using this example: Code: <script type="text/javascript"> function showInfo() { var elem = document.getElementById('verify'); if(document.forms[0].menu.value == "verify"){ elem.style.display="inline";} else{ elem.style.display="none";} } </script> </head> <body> <form action="#" method="post"> <select name="menu" onchange="showInfo()"> <option value="none">Select an option</option> <option value="email">Email</option> <option value="verify">Verify</option> </select> <div id="verify" style="display:none;"> <input type="text" value="Username" > <input type="password" value="password" > </div> </form> But what I do want, is that two differen things appear on the page and in the different location of the page. And this script does not read the second <div>. So the result is, that the only first <div> appears. Here are some images of what I want to do. Befo http://img82.imageshack.us/img82/7093/beforens9.jpg After http://img246.imageshack.us/img246/2759/afterzh2.jpg (what has to be changed is on the red circules). So can someone help me with this script?? Please! I am pritty noob to the javascript. Hi everyone, My website has 10 drop down lists. And I want to carry out form validation. I have written the code for form validation, but I am not sure where the code should be inserted, nor am I sure how to link it to the click of a submit button. My code (without the form validation function) is as follows: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>sample title</title> <script type = "text/javascript"> //<![CDATA[ var opts = []; var age, caste, profession, bachelor, master, doc, country, color, height, marriage, father; function formValues(form, ele) { var form = document.forms[form].elements[ele], val = form.value, index = form.selectedIndex; if (typeof opts[ele] === 'undefined') opts.push(ele); opts[ele] = form.options[index].text; } function processForm() { var set = [ {form: 'age', ele: 'groomage'}, {form: 'caste', ele: 'groomcaste'}, {form: 'profession', ele: 'groomprofession'}, {form: 'bachelor', ele: 'groombachelor'}, {form: 'doc', ele: 'groomdoc'}, {form: 'country', ele: 'groomcountry'}, {form: 'color', ele: 'groomcolor'}, {form: 'height', ele: 'groomheight'}, {form: 'marriage', ele: 'groommarriage'}, {form: 'father', ele: 'groomfather'} ]; for (var i in set) { formValues(set[i].form, set[i].ele); } switch (opts['groomage']) { case '23': age = 0.25; break; case '24': age = 0.35; break; case '25': age = 0.55; break; case '26': age = 0.75; break; case '27': age = 0.99; break; case '28': age = 0.85; break; case '29': age = 0.75; break; case '30': age = 0.65; break; case '31-35': age = 0.45; break; case '36-40': age = 0.35; break; default: age = 0.5; } switch (opts['groomcaste']) { case 'Bania': caste = 0.75; break; case 'Brahmin': caste = 0.99; break; case 'Labanas': caste = 0.75; break; case 'Rajput': caste = 0.85; break; case 'Maravar': caste = 0.80; break; case 'Kayastha': caste = 0.75; break; case 'Bhumihar': caste = 0.80; break; case 'Jat': caste = 0.65; break; case 'Kshatriya': caste = 0.75; break; case 'Kamma': caste = 0.90; break; case 'Reddy': caste = 0.95; break; case 'Vaishya': caste = 0.85; break; case 'Kappu': caste = 0.90; break; default: caste = 0.5; } switch (opts['groomprofession']) { case 'Doctor': profession = 0.85; break; case 'Family Business': profession = 0.65; break; case 'Engineer': profession = 0.75; break; case 'Lawyer': profession = 0.75; break; case 'CA': profession = 0.75; break; default: profession = 0.5; } switch (opts['groombachelor']) { case 'Less than 20,000': bachelor = 0; break; case '20,000 - 30,000': bachelor = 0.25; break; case '30,000 - 40,000': bachelor = 0.35; break; case '40,000 - 50,000': bachelor = 0.45; break; case '50,000 - 70,000': bachelor = 0.65; break; case '70,000 - 1 Lakh': bachelor = 0.75; break; default: bachelor = 0.5; } switch (opts['groomdoc']) { case 'Massachusetts Institute of Technology (MIT)': doc = 0.99; break; case 'Stanford': doc = 0.99; break; case 'Harvard': doc = 0.99; break; case 'Indian Instititute of Technology (IIT)': doc = 0.85; break; case 'Indian Instititute of Management (IIM)': doc = 0.90; break; case 'IIT + IIM': doc = 0.99; break; case 'None of the Above': doc = 0.35; break; default: doc = 0.55; } switch (opts['groomcountry']) { case 'USA': country = 0.99; break; case 'Any Country less developed than India': country = 0.11; break; case 'India': country = 0.55; break; case 'Any European Country/Any Country more developed than India': country = 0.99; break; default: country = 0.55; } switch (opts['groomcolor']) { case 'Pitch Black (Not visible on a moonless night)': color = 0.11; break; case 'Black': color = 0.25; break; case 'Brown': color = 0.35; break; case 'Wheatish (Almost White. Would need some Fair n Lovely)': color = 0.65; break; case 'Fairy White': color = 0.99; break; case 'White': color = 0.85; break; default: color = 0.5; } switch (opts['groomheight']) { case '5\'5"': height = 0.55; break; case '5\'6"': height = 0.65; break; case '5\'4"': height = 0.45; break; case '5\'7"': height = 0.70; break; case '5\'8"': height = 0.75; break; case '5\'9"': height = 0.80; break; case 'Less than 5\'4"': height = 0.11 break; case '5\'10"': height = 0.85; break; case '5\'11"': height = 0.85; break; case 'Greater than 6\'1"': height = 0.85; break; case '6': height = 0.99; break; case '6\'1"': height = 0.99; break; default: height = 0.5; } switch (opts['groommarriage']) { case 'More than 2': marriage = 0; break; case '2': marriage = 0.25; break; case '1': marriage = 0.45; break; case '0': marriage = 0.99; break; default: marriage = 0.5; } switch (opts['groomfather']) { case 'IAS': father = 0.99; break; case 'Family Business': father = 0.65; break; case 'Doctor': father = 0.85; break; case 'Lawyer': father = 0.75; break; case 'Engineer': father = 0.80; break; case 'CA': father = 0.75; break; case 'Engineer + MBA': father = 0.99; break; default: father = 0.5; } } window.onload = processForm; function processOrder() { processForm(); var total = 1.5*age + 3.25*bachelor + profession + 0.75*father + marriage + country + height + (doc + caste + color)/2; var pageNumber = Math.floor(total); //alert(pageNumber); window.open('Page ' + pageNumber + '.html'); } //]]> </script> </head> <body bgcolor="#ADD8E6"> <center> <font size="6"><strong>sample text 1</strong></font> </center> <br /><br /> <br /><br /> <em>*sample text 2</em> <center> <strong>Groom's Age</strong> <form name="age"> <select name="groomage" onclick="formValues('age', 'groomage')"> <option value="a1"></option> <option value="a2">23</option> <option value="a3">24</option> <option value="a4">25</option> <option value="a5">26</option> <option value="a6">27</option> <option value="a7">28</option> <option value="a8">29</option> <option value="a9">30</option> <option value="a10">31-35</option> <option value="a11">36-40</option> </select> </form> <br /> <strong>Groom's Caste</strong> <form name="caste"> <select name="groomcaste" onchange="formValues('caste', 'groomcaste')"> <option value="b1"></option> <option value="b2">Brahmin</option> <option value="b3">Bania</option> <option value="b4">Kayastha</option> <option value="b5">Kshatriya</option> <option value="b6">Bhumihar</option> <option value="b7">Maravar</option> <option value="b8">Reddy</option> <option value="b9">Kamma</option> <option value="b14">Kappu</option> <option value="b10">Jat</option> <option value="b11">Labanas</option> <option value="b12">Rajput</option> <option value="b13">Vaishya</option> </select> </form> <br /> <strong>Groom's Current Profession</strong> <form name="grofession"> <select name="groomprofession" onchange="formValues('profession', 'groomprofession')"> <option value="c1"></option> <option value="c2">Doctor</option> <option value="c3">Engineer</option> <option value="c4">Lawyer</option> <option value="c5">CA</option> <option value="c6">Family Business</option> <option value="c7">Teacher</option> <option value="c8">Journalist</option> <option value="c9">Business Analyst</option> </select> </form> <br /> <strong>Groom's Monthly Salary</strong> <form name="bachelor"> <select name="groombachelor" onchange="formValues('bachelor', 'groombachelor')"> <option value="d1"></option> <option value="d3">Less than 20,000</option> <option value="d4">20,000 - 30,000</option> <option value="d5">30,000 - 40,000</option> <option value="d6">40,000 - 50,000</option> <option value="d7">50,000 - 70,000</option> <option value="d8">70,000 - 1 Lakh</option> </select> </form> <br /> <strong>Groom's Alma Mater</strong> <form name="doc"> <select name="groomdoc" onchange="formValues('doc', 'groomdoc')"> <option value="f1"></option> <option value="f2">Massachusetts Institute of Technology (MIT)</option> <option value="f3">Stanford</option> <option value="f4">Harvard</option> <option value="f5">Indian Instititute of Technology (IIT)</option> <option value="f6">Indian Institute of Management (IIM)</option> <option value="f7">IIT + IIM</option> <option value="f8">None of the Above</option> </select> </form> <br /> <strong>The Groom is working in</strong> <form name="country"> <select name="groomcountry" onchange="formValues('country', 'groomcountry')"> <option value="g1"></option> <option value="g2">India</option> <option value="g3">USA</option> <option value="g4">Any European Country/Any Country more developed than India</option> <option value="g5">Any Country less developed than India</option> </select> </form> <br /> <strong>Groom's Skin Color</strong> <form name="color"> <select name="groomcolor" onchange="formvalues('color', 'groomcolor')"> <option value="h1"></option> <option value="h2">Fairy White</option> <option value="h3">White</option> <option value="h4">Wheatish (Almost White. Would need some Fair n Lovely)</option> <option value="h5">Brown</option> <option value="h6">Black</option> <option value="h7">Pitch Black (Not visible on a moonless night)</option> </select> </form> <br /> <strong>Groom's Height</strong> <form name="height"> <select name="groomheight" onchange="formvalues('height', 'groomheight')"> <option value="i1"></option> <option value="i2">Less than 5'4"</option> <option value="i3">5'5"</option> <option value="i4">5'6"</option> <option value="i5">5'7"</option> <option value="i6">5'8"</option> <option value="i7">5'9"</option> <option value="i8">5'10"</option> <option value="i9">5'11"</option> <option value="i10">6'</option> <option value="i11">6'1"</option> <option value="i12">Greater than 6'1"</option> </select> </form> <br /> <strong>Number of times the Groom has married before</strong> <form name="marriage"> <select name="groommarriage" onchange="formvalues('marriage', 'groommarriage')"> <option value="j1"></option> <option value="j2">0</option> <option value="j3">1</option> <option value="j4">2</option> <option value="j5">More than 2</option> </select> </form> <br /> <strong>Groom's Father's Profession</strong> <form name="father"> <select name="groomfather" onchange="formvalues('father', 'groomfather')"> <option value="k1"></option> <option value="k2">Engineer</option> <option value="k3">Doctor</option> <option value="k4">IAS</option> <option value="k5">Lawyer</option> <option value="k6">CA</option> <option value="k7">IAS</option> <option value="k8">Engineer + MBA</option> <option value="k9">Family Business</option> <option value="k10">None of the above</option> </select> </form> <br /> <input type="button" value="Calculate Dowry Amount" onclick="processOrder()" /> <br /> <br /> <center> <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="Plebeian42">Tweet</a> <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> </center> <br /> <div style="width: 100px; margin: 0 auto; padding: 4px;"> <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> </div> <br /><br /> </body> </html> The code for the FormValidation runs as follows (which I am not sure where to insert), and also not very sure whether it's the correct code or not. Code: function ValidateForm() { si = document.age.groomage.selectedIndex; si_1 = document.caste.groomcaste.selectedIndex; si_2 = document.profession.groomprofession.selectedIndex; si_3 = document.bachelor.groombachelor.selectedIndex; si_4 = document.doc.groomdoc.selectedIndex; si_5 = document.country.groomcountry.selectedIndex; si_6 = document.color.groomcolor.selectedIndex; si_7 = document.height.groomheight.selectedIndex; si_8 = document.marriage.groommarriage.selectedIndex; si_9 = document.father.groomfather.selectedIndex; if (document.age.groomage.options[si].text = " "; alert ('Please select Groom's Age'); if (document.caste.groomcaste.options[si_1].text = " "; alert ('Please select Groom's Caste'); if (document.profession.groomprofession.options[si_2].text = " "; alert ('Please select Groom's Profession'); if (document.bachelor.groombachelor.options[si_3].text = " "; alert ('Please select Groom's Salary'); if (document.doc.groomdoc.options[si_4].text = " "; alert ('Please select Groom's Alma Mater'); if (document.country.groomcountry.options[si_5].text = " "; alert ('Please select the country where Groom lives'); if (document.color.groomcolor.options[si_6].text = " "; alert ('Please select Groom's Skin Color); if (document.height.groomheight.options[si_7].text = " "; alert ('Please select Groom's Height'); if (document.marriage.groommarriage.options[si_8].text = " "; alert ('Please select number of times the Groom has married'); if (document.father.groomfather.options[si_9].text = " "; alert ('Please select Groom's Father's Profession'); } I would appreciate any kind of help. Thanks! Hello everyone! =] I need help with Javascript. I want to have a script that if one chooses to register for dinner, then validation will be performed to ensure whether the user have chosen that they are Vegetarian or not. If the user chooses not to attend dinner, then there is no need to validate the Vegetarian option. Here's the code: Code: <p>Register for Conference Dinner?<select type="text" name="conf_dinner" id="conf_dinner"> <option> Please Select </option> <option value="N">No</option> <option value="Y">Yes</option> </select></p> <p> Are you a vegetarian?<select type="text" name="vegetarian" id="vegetarian"> <option value="N">No</option> <option value="Y">Yes</option> </select></p> I have created this form. I would like to use javascript to mail the form to the selected email from the selection list when the submit button is pressed. could anyone help with this? <form name="Contact Us" id="contact" action="mailto:" method="post"> <fieldset id="selection"> Who would you like to email: <select> <option value="email1" >email1</option> <option value="email2" >email2</option> <option value="email3">email3</option> </select> <fieldset id="Name" > Name <input type="text" id="firstname" name="firstname"> <input type="text" id="email" name="email"> </fieldset> <fieldset id="question"> Comments and Questions <input type="text" id="comment" name="comment" style="width: 500; height: 300"> </fieldset> </form> Hi, I have a working contact form with 3 of the fields requiring validation and they work well. I have added extra fields to the form (StatusClass, Project, CameFrom). These 3 fields return fine but I need to validated them. My problem is that the new fields don't show in the behaviours/validate panel even though they are within the form tag. Can anyone give me any help and advice as to how to accomplish this? Many thanks Code below.... Code: <script type="text/JavaScript"> <!-- function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_validateForm() { //v4.0 var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } //--> </script > Code: <form action="contact_us.asp" method="post" name="contact" target="_parent" class="contentText" id="contact" onsubmit="MM_validateForm('FullName','','R','Telephone','','RisNum','Email','','RisEmail');return document.MM_returnValue"> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="54%" class="subHeader">Full Name* </td> <td width="46%" class="subHeader"><input name="FullName" type="text" id="FullName" /></td> </tr> <tr> <td class="subHeader">Company Name </td> <td class="subHeader"><input name="CompanyName" type="text" id="CompanyName" /></td> </tr> <tr> <td class="subHeader">Address</td> <td class="subHeader"><input name="Address1" type="text" id="Address1" /></td> </tr> <tr> <td class="subHeader"> </td> <td class="subHeader"><input name="Address2" type="text" id="Address2" /></td> </tr> <tr> <td class="subHeader"> </td> <td class="subHeader"><input name="Address3" type="text" id="Address3" /></td> </tr> <tr> <td class="subHeader">Postcode</td> <td class="subHeader"><input name="Postcode" type="text" id="Postcode" /></td> </tr> <tr> <td class="subHeader">Telephone Number* </td> <td class="subHeader"><input name="Telephone" type="text" id="Telephone" /></td> </tr> <tr> <td class="subHeader">Mobile Number </td> <td class="subHeader"><input name="Mobile" type="text" id="Mobile" /></td> </tr> <tr> <td height="25" class="subHeader">Email Address* </td> <td class="subHeader"><input name="Email" type="text" id="Email" /></td> </tr> <tr> <td height="30" class="subHeader">Status*</td> <td class="subHeader"><select name="StatusClass" id="StatusClass"> <option selected="selected">Please Choose</option> <option>Architect</option> <option>Interior Designer</option> <option>Private Client</option> <option>Student</option> <option>Trade Enquiry</option> </select> </td> </tr> <tr> <td height="23" class="subHeader">Project*</td> <td class="subHeader"><select name="Project" size="1" id="Project"> <option selected="selected">Please Choose</option> <option>Planning Stages</option> <option>New Build</option> <option>Refurbishment</option> <option>Barn Conversion</option> <option>No project - information only</option> </select> </td> </tr> <tr> <td height="37" class="subHeader">How did you hear about us?*</td> <td class="subHeader"><select name="CameFrom" size="1" id="CameFrom"> <option selected="selected">Please Choose</option> <option>Web Search</option> <option>Grand Designs</option> <option>Living Etc</option> <option>Home Building & Renovation</option> <option>Architect</option> <option>Friend/Family</option> <option>Magazine/Editorial</option> <option>Newspaper Article</option> <option>Trade Show/Exhibition</option> <option>Other</option> </select></td> </tr> <tr> <td height="24" class="subHeader">Brochure Request </td> <td class="subHeader"><input name="Brochure" type="checkbox" id="Brochure" value="checkbox" /></td> </tr> <tr> <td class="subHeader">Message</td> <td class="subHeader"><span class="style4"> <textarea name="Message" id="Message"></textarea> </span></td> </tr> <tr> <td class="subHeader"> </td> <td class="subHeader"><input name="Submit" type="submit" value="Submit" /></td> </tr> <tr> <td colspan="2" class="subHeader"><em>* Required fields</em></td> </tr> </table> </form> Can someone please help me with my JavaScript, my code below works for BillingAddress2 but it doesn't for ShippingAddress2 (when you click off the ShippingAddress2 form field it alerts undefined) these form fields are in the same form JS Code: $("input").blur(function () { if($(this).val() == '') { if($(this).attr("id") != 'BillingAddress2' && $(this).attr("id") != 'ShippingAddress2') { alert($(this).attr("item")); } } }); html parts of the form Code: Billing Address Line 2:<br /><INPUT type="text" id="BillingAddress2" name="BillingAddress2" title="text" class="notrequired" value="<%=Session("BillingAddress2")%>" maxlength="30" tabindex="4"> Shipping Address 2:<br /><INPUT type="text" id="ShippingAddress2" name="ShippingAddress2" title="" class="notrequired" value="<%=Session("ShippingAddress2")%>" maxlength="30" tabindex="12"> Hy everyone! It's a simple question. I need to create a drodbox menu in a way that when the thrid option is selected, it opens up a check box in the same form. How can that be done? Txs a lot! Hi, On a registration form I have 4 fields that are all dropdown select fields. NAME, CLASS-1, CLASS-2, CODE 1) I would like to activate the CLASS-1, CLASS-2, CODE fields only if the NAME IS Selected from the dropdown. 2) Also would like to make the CLASS-1, CLASS-2 as required fields if the NAME is selected from the dropdown. How can I achieve this? Can I use some kind of a server event to activate / deactivate the fields on the form? Please advice Thanks Vinny I have a registration form that I am working on in which I need to assign a price to each option in a selection box then write that price in the document. Then I have a radio button that will add (different amounts based on selection) to that price before it is written. Then I have another radio button that just needs to write a price based on its selection. Both of these values will be written and then totaled. (See below for a less confusing explanation) On HTML form: >drop down list (name courseName, value of selections 1,2,3,4) > radio button (name returnStudent, value of selections 1,2) > radio button (name bookNeeded, value of selections 1,2) Table (name totalprice) at the bottom of the form: price1: price of courseName plus returnStudent (td with name tuitionprice) price2: price of bookNeeded (td with name bookprice) Total of the above (td with name totalprice) This is what I am trying to make work... Code: var selectedCourse = document.onsiteRegistration.courseName.value; var selectedStudent = document.onsiteRegistration.returnStudent.value; function setTuition() { if (selectedCourse == "1" && selectedStudent =="1") { document.write("12345"); } if (selectedCourse == "1" && selectedStudent =="2") { document.write("54321"); } } Then in my HTML I have simply put this to call the function and write it where I need it to be placed. <script>setTuition()</script> I am trying to find some examples of something like this but all I am coming up with is shopping carts and that is not what I need here. I am fairly confident that I can program the second part (totaling) if I can only get the selections to populate the different prices for me. If someone could point me in the right direction I would be very grateful! Hi Within a classic asp webform (using vbscript) I would like part of the form (input boxes within table structure) to be specific/displayed depending on the users selection from the combo box in the row above. I think the best solution would be using Javascript can anyone suggest a solution or example code? Many thanks Sarah Hi, I have a page with a drop down and there are external js file that are included in the page which define handlers and other actions for onchange of this drop down. So if the selection in the drop down changes, we display a different color map (based on the selection). Now I have to pre-select an option on a specific page (which has been completed) and the drop down shows the correct selection, but the event is not fired (that changes the map color). Any idea what I need to do? Thanks Hi, I have two dropdown lists with the second one being dependent on the selection in the first. Options in list 1: 1,3 or 4 List two should be enabled when 3 or 4 is selected in list 1. So far so good, managed to get it to work with only one set of lists, but I actually have 18 of those sets in this form: Code: <select name="fw[$i]" id="fw[$i]"> <option value="1">FWH</option> <option value="3">links</option> <option value="4">rechts</option> <option value="0" selected></option> </select><br /> <select name="lie[$i]" id="lie[$i]" disabled="disabled" onchange="showBox($i,xxx);"> <option value="0" selected>---</option> <option value="1">gut</option> <option value="2">schlecht</option> <option value="3">Strafschlag</option> <option value="4">OB</option> </select> $i is my index generated by my PHP script and runs from 1 to 18. Everything works just fine as long as the index is not in play. With the index my function breaks, most probably due to my inability to extract the second parameter (xxx above) from the selection field. Here's my function, there could be something wrong there too with how exactly to specify the proper dropdown list to enable. Code: function showBox(field,val) { if (val > 1) { var box = 'lie[' + field + ']'; document.form1.box.disabled == false; } else { document.form1.box.disabled == true; } } Finally, I'm not that adept in javascript programming, more like a trial and error guy, how has hit the wall with this problem. Thanks in advance! Joe Hey all, I was just wondering if you could help me out with the following, I've done a bit of google searching but haven't come up with anything. Basically, there will be 3 drop down boxes (Option a, Option b, Option c) In each drop down box there will be 3 options (One, Two, Three) Whats a script I can use that will write on page :Yellow If they select: Option a - One Option b - One Option c - Three Of the script will write blue if they selection Option a - Two Option b - One Option c - One Hey everyone, I have a simple html form that asks a user to select a state from a drop down list. Later, in the same form, there's a question that needs to display an image of the state they previously selected from the drop down menu. How can I accomplish this using javaScript?
Hello Folks, Here is my dropdown menu: Code: <select name="peeps"> <option value="Frank Tompson">Frank Tompson</option> <option value="Henry Wilson">Henry Wilson</option> <option value="Bill Kent">Bill Kent</option> <option value="Jessi McDonald"> Jessi McDonald</option> <option value="John Hays">John Hays</option> How can i make it so if i click on John Hays a JavaScript pop up will say Hello John Hays, and if i click on Bill Kent a popup will say hello Bill Kent and if i click on any other name nothing happens? |