JavaScript - Make Sure A Field Is A Field
Hello,
I'd like to make sure that a field is a field: Code: if ( typeof( myField ) != "field" ) { } This doesn't work, and I can't seem to find the answer. I can know if a field is a checkbox, for example, but I don't how to find the broader category of "input field". Similar Tutorialshiiii, im new to javascripts . Can anyone help me to know that a javascript which is validating a phone number accepts only digits but if the text field is left empty it should accept the entry as an empty entry.... plz share knowledge u will be more knowledgeable Hi folks. Looking to see if anyone could tell me where I'm going wrong with this script... I'm trying to have a field automatically filled with the day of the week ("Monday", "Tuesday", "Wednesday" and so on), upon the user selecting a date from the datepicker jQuery. If this isn't clear, I'll clarify further down the page. Here is the script: Code: <script type="text/javascript"> jQuery(document).ready(function($){ $('input[name="item_meta[428]"]').change(function(){ var d = $('input[name="item_meta[428]"]').val(); var n = new Date(d).getDay(); if(n == 0) val v = 'Sunday'; else if(n == 1) val v = 'Monday'; else if(n == 2) val v = 'Tuesday'; else if(n == 3) val v = 'Wednesday'; else if(n == 4) val v = 'Thursday'; else if(n == 5) val v = 'Friday'; else if(n == 6) val v = 'Saturday'; $('input[name="item_meta[429]"]').val(v).change(); }); }); </script> I'm basically trying to say, if the user selected today (15/05/2012) in the field 428 it would fill the field 429 with "Tuesday". Again, if the user selected 18/05/2012 in the field 428 then it would automatically fill field 429 with "Friday". It's being done to work in conjunction with a wordpress plugin called Formidable Pro hence the item_meta[428] etc. Any assistance would be greatly appreciated. Sam. I have a text field, call it income, that when the input is > 0 I need to dynamically show the next text box, and if it is blank hide the next text box. I would like to use onBlur but can't seem to get it to work. Can I do this? Help I have a form with a postcode field in it I want to add a button or text link next to this field which if clicked on goes to the google maps url querying that postcode i.e. if the postcode text in the field (form not submitted) was SW1A 1AA then without submitting that form there would be a button / link next to it which when clicked on went to "http://maps.google.co.uk/?q=SW1A1AA" Pretty sure Java should be able to do this ? Here is my validation script from dreamweaver i also have it in php for server side. But I trying to get a checkbox to make a text field required when you select it. Right now I have it so when you hit submit whether the text field is filled out or whether the checkbox is selected or not the error message comes up no matter what i do please help. the link to the page is http://www.mark-10.com/inquiries2 Code: function validateCheckbox() { if(document.forms["form1"].sales.checked) { if(document.forms["form1"].telephone.value.length < 12) { // xxx-xxx-xxxx return false ; } else { return true; } } } function MM_validateForm() { //v4.0 if (document.getElementById){ 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=document.getElementById(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(!validateCheckbox()) { errors+="If checkbox checked, please include telephone number"; } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } } //--> Hi Experts, I have designed an online registration system for a non profit in ASP/SQL. After the members register for classes they are automatically redirected to an invoice page with class fees. At the bottom of the page I have a Total Fees field of all the classes. The member is supposed to pay this amount to our organization. Question: We decided to do an online payment this year and would like to calculate a 2% additional amount on the Total Fees. This amount is paid to the Payment Merchant site. We cannot afford to lose the 2% since we are a non profit. Would really appreciate if someone can tell me how to 1) Add a new field under the Total field 2) And calculate the 2% additional fees and do a Grand Total. Thanks in advance. I have two drop down fields. When I select any value in the first drop down i want the second dropdown to automatically populate the value related to the first one. For e.g i have the first field as name and the second field as measured in. If I select 'Potato' in the first dropdown then the second drop down should populate 'kg'. Please help.
Hi all, Thanks for reading. I'm having an issue trying to accomplish the following - I have a text field (field1) already displayed on the HTML page. However, there's a link where you can add additional text fields to the page as well. When the link is clicked, the second text field is added successfully (field2), and when the link is clicked again, the third text field (field3) is added successfully. However, the third field does not add itself to the page, and the text for anything greater than a third field also isn't displayed after. This obviously means that my "fields" variable is not working right, so I'm wondering, would anyone be able to assist me to help me get that variable processing correctly? Code: <script language="javascript"> fields = 1; function addMore() { if (fields = 1) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field2' size='25' /> <span>Field 2.</span>"; fields = 2; } else if (fields = 2) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field3' size='25' /> <span>Field 3.</span>"; fields = 3; } else { document.getElementById('addedMore').innerHTML = "Only 3 fields are allowed."; document.form.add.disabled=true; } } </script> Here is the code in my HTML - Code: <input type="text" name="field1" size="25" /> <span>Field 1.</span> <div id="addedMore"></div> <p class="addMore"><form name="add"><a onclick="addMore()">Add another field.</a></form></p> Thank you very much. Hi All, My boss asked me to create an Adobe form and I'm unsure how to code it to accomplish what he is asking. I'm working with an Adobe form that has required fields. FieldA is not required but if FieldA is filled in, FieldB would then become required. What would be the ideal way to code this? Thank you hello i'm trying that code and it don't work, i'm on it for sometime and i don't find why.. function test(truc) { if(truc.value != document.myform.pwd1.value) { alert("dididiid");} } </script> <form name="myform" method="post" action="www.somwhere.he"> <fieldset <label>Password</label><span><input name="pwd1" type="password"></span> <label>Username</label><span><input name="username" type="text" onblur="test(this) "></span> <label>Confirm Password</label><span><input name="pwd2" type="password"></span> <span><input type="submit"></span> </fieldset> </form> Hello, I am trying to create a function that tests to see if the text field that I create in my markup contains numbers. Please help. Thank you. So if the user enters a serial number in the "Serial_Number" field and hits enter I would like the cursor to move DOWN to the next "Serial_Number" field. Is this possible?? Tracy Code: <table> <tr> <td> Serial Number:<br> <input type = "text" size = "30" onclick = "this.select();" onChange = "updateField(this.name,this.id,this.value)"; value = "" name = "Serial_Number" class = "textfield" id = "Serial_Number.4853" > </td> <td>Cat Number:<br> <input type = "text" size = "30" onclick = "this.select();" onChange = "updateField(this.name,this.id,this.value)"; value = "" name = "Cat_Number" class = "textfield" id = "Cat_Number.4853" > </td> </tr> <tr> <td> Serial Number:<br> <input type = "text" size = "30" onclick = "this.select();" onChange = "updateField(this.name,this.id,this.value)"; value = "" name = "Serial_Number" class = "textfield" id = "Serial_Number.4854" > </td> <td> Cat Number:<br> <input type = "text" size = "30" onclick = "this.select();" onChange = "updateField(this.name,this.id,this.value)"; value = "" name = "Cat_Number" class = "textfield" id = "Cat_Number.4854" > </td> </tr> <tr> <td> Serial Number:<br> <input type = "text" size = "30" onclick = "this.select();" onChange = "updateField(this.name,this.id,this.value)"; value = "" name = "Serial_Number" class = "textfield" id = "Serial_Number.4855" > </td> <td>Cat Number:<br> <input type = "text" size = "30" onclick = "this.select();" onChange = "updateField(this.name,this.id,this.value)"; value = "" name = "Cat_Number" class = "textfield" id = "Cat_Number.4855" > </td> </tr> </table> Hi Guys, Using this code i have managed to get the query value from the url. code: PHP Code: <script type="text/javascript"> // Check referrer function getQuerystring(key, default_) { if (default_==null) default_=""; key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regex = new RegExp("[\\?&]"+key+"=([^&#]*)"); var qs = regex.exec(window.location.href); if(qs == null) return default_; else return qs[1]; } var refVal = getQuerystring('r'); </script> <div id="div-regForm"> <div class="form-title">Sign Up</div> <div class="form-sub-title">Earn points & then swap for prizes! FREE!</div> <form id="regForm" action="sign-up.php" method="post"> <table> <tbody> <tr> <td><label for="fname">First Name:</label></td> <td><div class="input-container"><input name="fname" id="fname" type="text" value="<?php print $_POST['fname']; ?>" /></div></td> </tr> <tr> <td><label for="lname">Last Name:</label></td> <td><div class="input-container"><input name="lname" id="lname" type="text" value="<?php print $_POST['lname']; ?>" /></div></td> </tr> <tr> <td><label for="email">Your Email:</label></td> <td><div class="input-container"><input name="email" id="email" type="text" value="<?php print $_POST['email']; ?>" /></div></td> </tr> <tr> <td><label for="pass">Password:</label></td> <td><div class="input-container"><input name="pass1" id="pass1" type="password" value="<?php print $_POST['pass1']; ?>" /></div></td> </tr> <tr> <td><label for="pass">Confirm Password:</label></td> <td><div class="input-container"><input name="pass2" id="pass2" type="password" value="<?php print $_POST['pass2']; ?>" /></div></td> </tr> <tr> <td><label for="cntry">Country:</label></td> <td><div class="input-container"><select name="cntry"><?php foreach($countryArray as $country) { print "<option value=\"$country\">$country</option>"; } ?></select></div></td> </tr> <tr> <td> </td> <td><input name="r" type="hidden" value="<script type="text/javascript">document.write(refVal);</script>" /><input type="submit" class="greenButton" name="submitSignUp" value="Sign Up" /></td> </tr> </tbody> </table> </form> </div> in this part value="<script type="text/javascript">document.write(refVal);</script>" /> i can't seem to put the value in the hidden field it print fine in the code just above. thanks for any help guys Graham Hello i am using a simple calendar date picker in which when u click a date is displayed in an input field. Using a javascript i am trying to retrieve data from a second page using this value but probably i am doing something wrong. 1st page: Code: <script type="text/javascript"> function showCustomer(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","check6.asp?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> Check in: <input onchange="showCustomer(this.value)" size="22" id="f_date1" /><button id="f_btn1">...</button> <script type="text/javascript">//<![CDATA[ var cal = Calendar.setup({ onSelect: function(cal) { cal.hide() }, showTime: true }); cal.manageFields("f_btn1", "f_date1", "%Y-%m-%d"); //]]></script> </form> <br /> <div id="txtHint">here...</div> </body> </html> and in second one i am trying to get date like this: Code: sql_cmd.CommandText = "SELECT dbo.rooms.id, type, image, price,details FROM dbo.rooms, dbo.transactions WHERE dbo.rooms.id=dbo.transactions.roomid and '" & request.querystring("q") & "' not between checkin and checkout" Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 2</title> </head> <script type="text/javascript"> var strWord = document.myForm.txtWord.value; function validateWord() { while(strWord == document.formname.myForm.value.length > 8 && var ichars = "PJ" ); { alert ("OK."); } } </SCRIPT> <form name="myForm" action="" method="" onsubmit="return false"> <p> <input name="txtWord" size="25" value="Enter Word Here"> </p> <p> <input type="button" value="Validate The Word" name="cmdValidateWord" onclick ="validateWord()"> </p> </html> Hi, I'm having trouble getting this code to work. It needs to check if the user has entered the correct characters into a field. A valid word should have a P at the start, and contain a J somewhere in it. If the word is valid, a box pops up saying "OK" once the user has clicked the ValidateWord button. It also needs to keep this kind of structure (ie. a while construct & validated through pressing a button). This is purely for personal education about performance of "while" constructs for field validation. Any help is hugely appreciated. How can I add a form field value to a url. I tried the below but it no work. Code: href="index2.php?q=4&id=+document.theForm.lists.value+&picklist" Hi. I'm having some trouble with validating all my fields in my form. I'm posting my code here. Code: function validateForm() {var chk = document.forms["EntryPage"]["studentname"].value; if (chk==null || chksdtnm=="") { alert("Student name must be filled out"); return false; } if (chk==null || chksdtnm=="") { alert("Student ID must be filled out"); return false; } } I need to alert the user with a messagebox for six fields if ever they're not filled in. How do I achieve that? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="javascript/text"> <!-- function clearInputField( input, def ) input = document.getElementById( input ); if ( input.value == def ) { input.value = ''; } } --> </script> </head> <body> <b>Testing Input</b> <input id="input" onclick="JavaScript: clearInputField('input', 'Enter Text');" type="text" size="31" value="Enter Text" /> <body> </html> This gives me a "Uncaught ReferenceError: clearInputField is not defined" error and I'm not sure why...? I am trying to calculate age based on the date of birth input into a text field. the date field should allow users to enter a one or two digit month, one or two digit date and a two or four digit year. Users should be able to enter any of the following date formats: 11-2-10, 1-25-2010, or 01/25/2010. On some days it works and others it wont, like 11-1-91 returns that the user is under 18. Code: function checkAge(){ var stDate = document.getElementById("birth").value; var dayPartToDate = parseInt(stDate.substring(0,2),10); var monPartToDate = parseInt(stDate.substring(3,5),10); var yearPartToDate = parseInt(stDate.substring(6,10),10); var dtTo = new Date(yearPartToDate, monPartToDate-1, dayPartToDate); var mydate = new Date(); mydate.setDate(mydate.getDate()); var bday = dtTo - mydate if (bday < 18){ window.alert("You must be 18 to rent equipment."); document.getElementById("birth").value = ""; } } Hi Guys, Someone please help me how to add new function to remove the field, i have js script function that add new field as follows Code: <script language="javascript"> fields = 0; function addInput() { if (fields != 10) { var htmlText = " <input type='text' name='friends[]' value='' size='auto' maxlength='45' /><br />"; var newElement = document.createElement('div'); newElement.id = 'new_field'; newElement.innerHTML = htmlText; var fieldsArea = document.getElementById('new_field'); fieldsArea.appendChild(newElement); fields += 1; } else { alert("Only 10 fields allowed."); document.form.add.disabled=true; } } </script> but i need some helps to add new functions for removing field, For any suggest and pointer would be appreciate. |