JavaScript - Registration Script
Sup gents
Can someone please tell me whats wrong with this code? The user is supposed to input a pass and script needs to check the array to see if such a pass exists in the array and confirm. Im building a sign in system for my website and this is the first step. Dont mind the global values in the beginning i plan to use them later while applying restrictions. Code: <html> <head> <script type ="text/JavaScript"> var counter = 0; var trial = 0; var base = 0; var choice = 0; var array2[] = {"1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009"}; var searchKey = searchform.inputVal.value; function pass() { for (var i =0; i < array2.length; i++) { if (array2[i] == searchkey ) searchform.result.value = "correct password"; } else return -1; } </script> </head> <body> <form name = "searchform" action = ""> <p>Enter password<br /> <input name = "inputVal"/> <input name = "search" type = "button" value = "Search" onclick = "pass()" /><br /></p> <p>Result<br /> <input name = "result" type = "text" size = "30" /></p> </form> </body> </html> Similar TutorialsThis is a bit of a lazy post but hey, Currently i have an awful lot of checks that run the same check on different variables. Simple Request... Can anyone see an obvious way (which i have clearly missed) to clean up and reduce the amount of code in the below. Code: <? // required code for every page. require($_SERVER['DOCUMENT_ROOT'] . '/scripts/required.php'); // end of required code for every page if(isset($_POST['sbmt'])) { // get variables $new_user = trim($_POST['user']); $new_pass = $_POST['newpass']; $con_pass = $_POST['conpass']; $new_fname = trim($_POST['fname']); $new_email = $_POST['email']; $con_email = $_POST['conemail']; $agree = $_POST['agree']; $level = $_POST['level']; $ip = @$_SERVER['REMOTE_ADDR']; // add slashes $new_user = addslashes($new_user); // encrypt $new_pass_e = hash('ripemd160',$new_pass); $con_pass_e = hash('ripemd160',$con_pass); // check username exists // connect to database $con = mysql_connect(DBHOST, DBUSER, DBPASS); if(!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db(DBNAME, $con); // get row for user $result = mysql_query("SELECT * FROM tUsers WHERE username='$new_user'"); $row = mysql_fetch_array($result); // kill connection mysql_close($con); // check username exists if($row['username']!=null) $user_error = 'Username already in use.<br />'; else $user_error = null; // check email is available // connect to database $con = mysql_connect(DBHOST, DBUSER, DBPASS); if(!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db(DBNAME, $con); // get row for user $result = mysql_query("SELECT * FROM tUsers WHERE email='$new_email'"); $row = mysql_fetch_array($result); // kill connection mysql_close($con); // check email is available if($row['email']!=null) $email_error = 'Email already in use.<br />'; else $email_error = null; // check lengths if(strlen($new_user)<3) $user_len_error = 'Username must be at least 3 characters<br />'; else $user_len_error = null; if(strlen($new_pass)<6) $pass_len_error = 'Password must be at least 6 characters<br />'; else $pass_len_error = null; if(strlen($new_fname)<6) $fname_len_error = 'Your name must be at least 6 characters<br />'; else $fname_len_error = null; // preg matches if(!preg_match('/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $new_email)) $email_preg_error = "Email is not valid.<br />"; else $email_preg_error = null; if(!preg_match('/[a-zA-Z]+\s+[a-zA-Z]+/',$new_fname)) $fname_preg_error = 'Name must containt at least one space.<br />'; else $fname_preg_error = null; // check matches if($new_pass != $con_pass) $pass_match_error = 'The passwords do not match.<br />'; else $pass_match_error = null; if($new_email != $con_email) $email_match_error = 'The emails do not match.<br />'; else $email_match_error = null; // build error list $errorlist = $user_error; $errorlist .= $email_error; $errorlist .= $user_len_error; $errorlist .= $pass_len_error; $errorlist .= $fname_len_error; $errorlist .= $email_preg_error; $errorlist .= $fname_preg_error; $errorlist .= $pass_match_error; $errorlist .= $email_match_error; // set expirey to a month $expire = 0; // set error list cookie setcookie('errorlist',$errorlist,$expire,'/'); // reload register.php header('Location:' . URL . '/register.php'); } ?> The required file is just a series of defines for items like the dbhost, dbusername, dbname, url etc etc. Cheers p.s. I want to add an if statement for if $errorlist=null then do bla else bla... in order for errorlist to be null... do i actually need to define the individual error messages as null. That could get rid of a lot of: else $<error name>=null; I'm pretty sure I can but i'd like to check first. Anybody help to start out this code: Create a "nag" counter that tells users to register. Save the counter in a cookie and display a message reminding users to register every fifth time they visit your site. There are four other parts to this task that I know how to do. I cannot find anything close to this in our book referencing a nag-counter or something similar to it. Thanks, in advance. Regards, AO5431 Hello, i got a problem with form like this: https://www2.giocarena.com/it-IT/Register/Start.aspx It's possible to set the field Cod Referent????? I've tried with this: <form name="aspForm" method="post" action="https://www2.giocarena.com/it-IT/Register/Start.aspx" target="_blank"> <input type="hidden" name="ctl00$cphBaseContainer$ctl00$txt_code" value="44411122224322445"></input> <button type="submit"> Nome </button> </form> Thank you!Thank you, thank you! <?php require('connect.php'); if($_POST['reg1']=="Register") { $stmt1="insert into regtable(fname,lname,c_addr,p_addr,phno,email,dob,gender,qual,wexp,usertype,btype,uname,pwd) values('$name1','$name2','$add1','$add2','$phno1','$email1','$dob1','$gend1','$qual1','$wexp1','$uty pe','$batch1','$user','$upwd')"; $res1=mysql_query($stmt1,$con);} ?> <html> <head> <script type="text/javascript"> function validate() { f=0; if(document.getElementById('fname').value=="") { document.frm1.fname.style.border='1px solid red'; //document.frm1.fname.style.background='#FFFFCC'; document.frm1.fname.focus(); document.getElementById('d_fname').style.visibility="visible"; document.getElementById('d_fname').innerHTML="Enter First Name"; } else { f++; } if(document.getElementById('lname').value=="") { document.frm1.lname.style.border='1px solid red'; document.frm1.lname.focus(); document.getElementById('d_lname').style.visibility="visible"; document.getElementById('d_lname').innerHTML="Enter Last Name"; } else { f++; } if(document.getElementById('addr1').value=="") { document.frm1.addr1.style.border='1px solid red'; document.frm1.addr1.focus(); document.getElementById('d_cadd').style.visibility="visible"; document.getElementById('d_cadd').innerHTML="Enter Contact Address"; } else { f++; } if(document.getElementById('pno').value=="") {document.frm1.pno.style.border='1px solid red'; document.frm1.pno.focus(); document.getElementById('d_pno').style.visibility="visible"; document.getElementById('d_pno').innerHTML="Enter Phone Number"; } else { f++; } if(document.getElementById('emid').value=="") {document.frm1.emid.style.border='1px solid red'; document.frm1.emid.focus(); document.getElementById('d_emid').style.visibility="visible"; document.getElementById('d_emid').innerHTML="Enter Email Id"; } else {f++; } if(document.getElementById('day').value=="0") { document.frm1.day.style.border='1px solid red'; document.getElementById('d_dob').style.visibility="visible"; document.getElementById('d_dob').innerHTML="Invalid Date"; } else { f++; } if(document.getElementById('month').value=="0") { document.frm1.month.style.border='1px solid red'; document.getElementById('d_dob').style.visibility="visible"; document.getElementById('d_dob').innerHTML="Invalid Date"; } else { f++; } if(document.getElementById('year').value=="0") { document.frm1.year.style.border='1px solid red'; document.getElementById('d_dob').style.visibility="visible"; document.getElementById('d_dob').innerHTML="Invalid Date"; } else {f++; } if((document.getElementById("gender1").checked!=true) && (document.getElementById("gender2").checked!=true)) { //document.frm1.gender.style.border='1px solid red'; document.getElementById('d_gender').style.visibility="visible"; document.getElementById('d_gender').innerHTML="Select Gender"; } else { f++; } if((document.getElementById("qual1").checked!=true) && (document.getElementById("qual2").checked!=true) && (document.getElementById("qual3").checked!=true) && (document.getElementById("qual4").checked!=true)) { //document.frm1.gender.style.border='1px solid red'; document.getElementById('d_qual').style.visibility="visible"; document.getElementById('d_qual').innerHTML="Select Qualification"; } else {f++; } if(document.getElementById('wexp').value=="") { document.frm1.wexp.style.border='1px solid red'; //document.frm1.emid.focus(); document.getElementById('d_wexp').style.visibility="visible"; document.getElementById('d_wexp').innerHTML="Select Work Experience"; } else {f++;} if(document.getElementById('utype').value=="") { document.frm1.utype.style.border='1px solid red'; document.getElementById('d_utype').style.visibility="visible"; document.getElementById('d_utype').innerHTML="Select Usertype"; } else {f++; } if(document.getElementById('btype').value=="") { document.frm1.btype.style.border='1px solid red'; //document.frm1.emid.focus(); document.getElementById('d_btype').style.visibility="visible"; document.getElementById('d_btype').innerHTML="Select Batch"; } else {f++; } if(document.getElementById('uname').value=="") { document.frm1.uname.style.border='1px solid red'; document.frm1.uname.focus(); document.getElementById('d_uname').style.visibility="visible"; document.getElementById('d_uname').innerHTML="Enter Username"; } else {f++; } if(document.getElementById('pwd').value=="") { document.frm1.pwd.style.border='1px solid red'; document.frm1.pwd.focus(); document.getElementById('d_pwd').style.visibility="visible"; document.getElementById('d_pwd').innerHTML="Enter Password"; } else {f++; } if(document.getElementById('rpwd').value=="") { document.frm1.rpwd.style.border='1px solid red'; document.frm1.rpwd.focus(); document.getElementById('d_rpwd').style.visibility="visible"; document.getElementById('d_rpwd').innerHTML="Retype Password"; } else { f++; } if(f==15) {return true;} else { return false;} } /*function nameval() { var fnm=document.getElementById('fname').value; var pat=/\d\g; if(fnm.match(pat)) { alert("Only characters are allowed"); } }*/ function phonval() { var ph=document.getElementById("pno").value; var pat=/\s/g; var ex=/\D/g; str=""; if(ph.match(ex)) { // alert ("Invalid Phone"); str=str+ "Phone number should be digits"; document.getElementById('pno').value=""; } else if(ph.length!=10) { str=str+"Phone number should be of 10 digits" //alert("Phone number should be of 10 digits"); } /*else if(ph.match(pat)) { str=str+"Phone number cannot have blank spaces"; //alert("Phone number cannot have blank spaces"); } */ if(str.length!=0) { alert(str);} } function emailval() { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = document.getElementById('emid').value; if(reg.test(address) == false) { alert('Invalid Email Address'); return false; } } </script> </head> <body id="www-url-cz" onload="inactive()"> <h2><img src="design/icon-registration.png" height="70px" \>Registration Form</h2> <form name="frm1" method="post"> <table style="padding-top:50px;"> <tr> <th align="left">First Name</th> <td><input type="text" name="fname" id="fname" size="27" class="border"></td> <td class='err'><div id="d_fname"></div></td> </tr> <tr></tr> <tr> <th align="left">Last Name</th> <td><input type="text" name="lname" id="lname" size="27" class="border"></td> <td class='err'><div id="d_lname"></div></td> </tr> <tr></tr> <tr> <th align="left">Contact Address</th> <td><textarea rows="5" cols="20" name="addr1" id="addr1" class="border"></textarea></td> <td class="err"><div id="d_cadd"></div></td> </tr> <tr></tr> <tr> <th align="left">Permanent Address</th> <td><textarea rows="5" cols="20" name="addr2" id="addr2" class="border"></textarea></td> <td class='err'><div id="d_padd"></div></td> </tr> <tr></tr> <tr> <th align="left">Phone Number</th> <td><input type="text" name="pno" id="pno" size="27" class="border" onblur="phonval()"></td> <td class='err'><div id="d_pno"></div></td> </tr> <tr></tr> <tr> <th align="left">Email id</th> <td><input type="text" name="emid" id="emid" size="27" class="border" onblur="return emailval()"></td> <td class='err'><div id="d_emid"></div></td> </tr> <tr></tr> <tr> <th align="left">Date of Birth</th> <td colspan="3"> <select name="day" id="day" class="border" onchange="dat_day()"> <option value="0">Day</option> <script type="text/javascript"> for(i=1;i<=31;i++) { document.write("<option value="+i+">"+i+"</option>"); } </script> </select> <select name="month" id="month" class="border" onchange="dat_month()"> <option value="0">Month</option> <option value="1">Jan</option> <option value="2">Feb</option> <option value="3">Mar</option> <option value="4">Apr</option> <option value="5">May</option> <option value="6">June</option> <option value="7">Jul</option> <option value="8">Aug</option> <option value="9">Sep</option> <option value="10">Oct</option> <option value="11">Nov</option> <option value="12">Dec</option> </select> <select name="year" id="year" class="border" onchange="dat_year()"> <option value="0">Year</option> <script type="text/javascript"> for(i=1975;i<=1996;i++) { document.write("<option value="+i+">"+i+"</option>") } </script> </select><div class="err" id="d_dob"></div> </td> <!--<td class="err"><div id="d_dob"></div></td>--> </tr> <tr></tr> <!--<tr> <th align="left">Age</th> <td><input type="text" name="age id="age" size="27" class="border"></td> </tr>--> <tr> <th align="left">Gender</th> <td colspan="3"> Male<input type="radio" value="male" name="gender" id="gender1"> Female<input type="radio" value="female" name="gender" id="gender2"> <div class="err" id="d_gender"></div> </td> <!--<td class='err'><div id="d_gender"></div></td>--> </tr> <tr></tr> <tr> <th align="left">Qualification</th> <td colspan="5"> SSLC<input type="radio" value="sslc" name="qual" id="qual1"> Plus Two<input type="radio" value="plus_two" name="qual" id="qual2"> Degree<input type="radio" value="degree" name="qual" id="qual3"> PG<input type="radio" value="pg" name="qual" id="qual4"> <div class="err" id="d_qual"></div> </td> <!--<td class='err'><div id="d_qual"></div></td>--> </tr> <tr></tr> <tr> <th align="left">Work Experience(in years)</th> <td colspan="2"><select name="wexp" id="wexp" class="border"> <option value=''>Select One</option> <script type="text/javascript"> for(var i=0;i<=15;i++) { document.write("<option value="+i+">"+i+"</option>"); } </script> <option>More than 15 years</option> </select> <div id="d_wexp" class="err"></div> </td> <!--<td class='err'><div id="d_wexp"></div></td>--> </tr> <tr></tr> <tr> <th align="left">User Type</th> <td><select name="utype" id="utype" class="border"> <option value=''>Select One</option> <option value='admin'>Administrator</option> <option value='trainer'>Trainer</option> <option value='trainee'>Trainee</option> </select> </td> <td class='err'><div id="d_utype"></div></td> </tr> <tr></tr> <tr> <th align="left">Batch Type</th> <td><select multiple="multiple" size="0" name="btype" id="btype" class="border"> <option value=''>Select One</option> <?php while($row=mysql_fetch_array($result)) { ?> <option value="<?php echo $row['batchtypeid']?>"><?php echo $row['batchtype'] ?></option> <?php } ?> </select> </td> <td class='err'><div id="d_btype"></div></td> </tr> <tr></tr> <!-- <tr> <th align="left">Batch Code</th> <td> <select multiple="multiple" size="0" name="bcode" id="bcode" class="border">--> <!--<option value="">Select One</option>--> <!--</select> </td> <td class='err'><div id="d_bcode"></div></td> </tr>--> <tr></tr> <tr> <th align="left">Username</th> <td><input type="text" name="uname" id="uname" size="27" class="border"></td> <td class='err'><div id="d_uname"></div></td> </tr> <tr></tr> <tr> <th align="left">Password</th> <td><input type="password" name="pwd" id="pwd" size="27" class="border"></td> <td class='err'><div id="d_pwd"></div></td> </tr> <tr></tr> <tr> <th align="left">Retype Password</th> <td><input type="password" name="rpwd" id="rpwd" size="27" class="border"></td> <td class='err'><div id="d_rpwd"></div></td> </tr> <tr> <td></td> </tr> <tr></tr> <tr> <td></td> <td><input type="submit" value="Register" name="reg1" id="reg1" onclick="return validate()" ></td> </tr> </table></form></div> I have a piece of JavaScript code that should validate that a username field is not empty or null and that a telephone field is in the correct format using event handler registration. It seems to be validating fine but if there is an error it still manages to submit. HTML Code: <html> <head> <script type = "text/javascript" src = "js/validator.js" > </script> </head> <body> <form id = "decorForm" action = ""> <table border = "0"> <tr> <th>Username: </th> <td> <input type = "text" id = "myUserName" size = "15" maxlength = "15"/> </td> </tr> <tr> <th>Telephone: </th> <td> <input type = "text" id = "telephone" name = "telephone" size = "15" maxlength = "13"/> <br /> (999)999-9999 </td> </tr> <tr> <td> <input type = "submit" value = "Submit" /> </td> <td> <input type = "reset" value = "Reset" /> </td> </tr> </table> </form> <script type = "text/javascript" src = "js/validatorr.js" > </script> </body> </html> JAVASCRIPT (validator.js) Code: function chkUser() { // Verifies that the UserName field is not empty. var myUserName = document.getElementById("myUserName"); if (myUserName.value == "" || myUserName.value == null) { alert ("Please enter a Username!"); return false; } else { return true; } } function chkTelephone() { // Verifies that the Telephone field value is in the correct format. var tel = document.getElementById("telephone"); var pos = tel.value.search(/^\(\d{3}\)\d{3}-\d{4}$/); if (pos != 0) { alert ("Please enter telephone number in the following format: (999)999-9999"); return false; } else { return true; } } function chkFields() { // Verifes all fields and returns boolean to event handler // The event handler function if (chkUser() && chkTelephone()) { return true; } else { return false; } } JAVASCRIPT (validatorr.js) Code: //Register the event handlers for validator.js document.getElementById("decorForm").onSubmit = chkFields; I am trying to use this as an example. Hi All, I have two scripts which I want to try and integrate. I am using a nice gallery script to show thumbnails which are appended to a an image wrapper which on click of the thumbnail shows the larger image in the image wrapper, I am trying to implement cloud zoom which is a plugin which uses image srcs to then point to an anchor href to show another larger zoom image either in the same place.. which is what I am trying to do or in another div beside. I have had to set me img srcs up in a certain way to easily enter some product details. and I need to try an manipulate the code to make it work to suit my file layout. I am using a var= images [ with a series of file locations and info such as below { src: 'romanticabride/thumbs/tn_Shauna.jpg', srcBig: 'romanticabride/images/Shauna.jpg', title: 'Shauna', longDescription: '<b><H1>Shauna</H1></b><br><b>Romantica Of Devon <br><br><h2>Sizes Available:</h2><br> 6 - 32.<b><br><b><br><b><b><b><H2>Colours Available:</h2><b><br>Various<br>Please Enquire Below<br><br><br><br><a href="mailto:tracy@cherishbridal.co.uk?subject=Web Enquiry Regarding Romantica Shauna Bridal Gown"class="enquiry rose glow" >Click To Enquire About This Item </a>' }, what I need is for cloud zoom to work when the main image wrapper is hovered over which means it will need to add a class or when the whichever srcBig: is hovered over it gets wrapped by href to make the script work . one of my pages is http://www.cherishbridal.co.uk/romaticabride.html the cloud zoom script is at http://www.professorcloud.com/mainsite/cloud-zoom.htm.. I am happy to share a jsfiddle with someone or explain further or post some code. Thank you in advance I have a script that works in seamonkey(my html editor) but when I use it in IE8 it says errors happen. Here's the code (the first line is on line 7 of the html file): Code: <script type="text/javascript"> function enlarge(imageNum) { var numToString = ""; if(parseInt(imageNum) < 10){ numToString = "0" + imageNum; } else { numToString = imageNum + ""; } window.open("images/LgScreenshot"+numToString+".jpg","Screenshot "+imageNum,"status=0,height=675,width=900,resizable=0"); } </script> And the errors: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB0.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; InfoPath.3; .NET CLR 3.0.30729) Timestamp: Wed, 10 Feb 2010 14:58:16 UTC Message: Object expected Line: 150 Char: 1 Code: 0 URI: http://samssc2site.co.cc/Features.html Message: Invalid argument. Line: 18 Char: 1 Code: 0 URI: http://samssc2site.co.cc/Features.html does any expert know how to pass parameters in the <script ..> tag? for instance; Code: <script type="text/javascript" src="script.js ?param1=val1¶m2=val2&etc "> in the javascript script.js, how would we read the params after the question mark? for example, google this; google shopping cart /v2_2/cart.js I need to assign a key in the javascript to actually make the javascript work,. I have a bookmark in chrome , a javascript , which actually works when clicked on it .,. but how can i edit it so that i can actually make it work on click a key or combination of keys. i want to declare the key or keycombo in the script itself .,. the script is for catching the selected text on the webpage and opening a new tab(or window) and doing an exact search search of the selected text using google.com .,., So I want it to work it this way ., select the text press a key and it opens a new tab (or window) with an xact search .,. i want to declare the key or keycombo in the script itself .,. the script is for catching the selected text on the webpage and opening a new tab(or window) and doing an exact search search of the selected text using google.com .,., So I want it to work it this way ., select the text press a key and it opens a new tab (or window) with an xact search .,. Thanks in advance ., Nani On this website: http://evancoleman.net/index.php I really like on the top how the menu has like 5 or 6 icons, and when you hover over them it shows a bubble with the name in them. Does anybody know where I can find this script? Thanks. Hello again . If these questions concerning Regular Expressions are inappropriate in this forum please let me know . Thank You. This expression <script[^>]*>.*?</script> matches ... Code: <script type="text/javascript">var cnnIsHomePage = true;</script> but not ... Code: <script type="text/javascript"> var cnnIsHomePage = true; </script> Please , how can i match the latter ? I have new script and i need to fix it for : 1-This script opens windows behind current windows when visitor clicks everywhere on the page . I need it works when visitors click only on links not everywhere on the page 2-i need it works for links with speacial id's , not every links <script type="text/javascript"> var puShown = false; function doOpen(url) { if ( puShown == true ) { return true; } win = window.open(url, 'ljPu', 'toolbar,status,resizable,scrollbars,menubar,location,height=680,width=790'); // win = window.open(url, 'ljPu', 'height=680,width=790'); if ( win ) { win.blur(); puShown = true; } return win; } function setCookie(name, value, time) { var expires = new Date(); expires.setTime( expires.getTime() + time ); document.cookie = name + '=' + value + '; expires=' + expires.toGMTString(); } function getCookie(name) { var cookies = document.cookie.toString().split('; '); var cookie, c_name, c_value; for (var n=0; n<cookies.length; n++) { cookie = cookies[n].split('='); c_name = cookie[0]; c_value = cookie[1]; if ( c_name == name ) { return c_value; } } return null; } function initPu() { if ( document.attachEvent ) { document.attachEvent( 'onclick', checkTarget ); } else if ( document.addEventListener ) { document.addEventListener( 'click', checkTarget, false ); } } function checkTarget(e) { if ( !getCookie('popundr') ) { var e = e || window.event; var win = doOpen('go.php?link=trade2'); setCookie('popundr', 1, 1*60*60*1000); } } initPu(); </script> Hello all. I have a pretty important question. I am building a webapp for the iPad and I need to be able to drag divs around the page for it to work. I had this script which works in desktop browsers: Code: function Browser() { var ua, s, i; this.isIE = false; this.isNS = false; this.version = null; ua = navigator.userAgent; s = "MSIE"; if ((i = ua.indexOf(s)) >= 0) { this.isIE = true; this.version = parseFloat(ua.substr(i + s.length)); return; } s = "Netscape6/"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = parseFloat(ua.substr(i + s.length)); return; } // Treat any other "Gecko" browser as NS 6.1. s = "Gecko"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = 6.1; return; } } var browser = new Browser(); // Global object to hold drag information. var dragObj = new Object(); dragObj.zIndex = 0; function dragStart(event, id) { var el; var x, y; // If an element id was given, find it. Otherwise use the element being // clicked on. if (id) dragObj.elNode = document.getElementById(id); else { if (browser.isIE) dragObj.elNode = window.event.srcElement; if (browser.isNS) dragObj.elNode = event.target; // If this is a text node, use its parent element. if (dragObj.elNode.nodeType == 3) dragObj.elNode = dragObj.elNode.parentNode; } // Get cursor position with respect to the page. if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; } // Save starting positions of cursor and element. dragObj.cursorStartX = x; dragObj.cursorStartY = y; dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10); dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10); if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0; if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0; // Update element's z-index. dragObj.elNode.style.zIndex = ++dragObj.zIndex; // Capture mousemove and mouseup events on the page. if (browser.isIE) { document.attachEvent("onmousemove", dragGo); document.attachEvent("onmouseup", dragStop); window.event.cancelBubble = true; window.event.returnValue = false; } if (browser.isNS) { document.addEventListener("mousemove", dragGo, true); document.addEventListener("mouseup", dragStop, true); event.preventDefault(); } } function dragGo(event) { var x, y; // Get cursor position with respect to the page. if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY; } // Move drag element by the same amount the cursor has moved. dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px"; dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px"; if (browser.isIE) { window.event.cancelBubble = true; window.event.returnValue = false; } if (browser.isNS) event.preventDefault(); } function dragStop(event) { // Stop capturing mousemove and mouseup events. if (browser.isIE) { document.detachEvent("onmousemove", dragGo); document.detachEvent("onmouseup", dragStop); } if (browser.isNS) { document.removeEventListener("mousemove", dragGo, true); document.removeEventListener("mouseup", dragStop, true); } } And then I put this into the body section of the page: Code: <div id="boxA" class="box" style="left:400px;top:150px;"> <div class="bar" style="width:12em;" onmousedown="dragStart(event, 'boxA')">Drag Box B</div> <div class="content" style="width:12em;"> Enter stuff to be dragged here. </div> </div> The iPad doesn't read "onmousedown" correctly though, so I need another attribute to be put there instead. I tried "onclick" and then viewed it on the iPad and I was able to click on the div, then click around the page and the div would move there. If I use "onclick" though, something has to tell the browser that once I've clicked it once it stops moving if I click somewhere on the page. Like I said, if you can help, great! Quote: function hTools() { var hTools = new Array(6); hTools[0] = "hand tools"; hTools[1] = "saw"; hTools[2] = "hammer"; hTools[3] = "screwdriver"; hTools[4] = "wrench"; hTools[5] = "pliers"; } if(hTools[0] == true) { document.forms[0].item_one.value ="0"; } else if(hTools[1] == true) { document.forms[0].item_one.value ="$20.00" } then I call it fro an onchage selection list Quote: <p><select name ="hTool" onchange ="return hTools();"> <option value ="hTool0">Hand Tool</option> Quote: Item 1: <input type ="text" name ="item_one" My script or my call or both is not working could you please look at it and tell me what I am doing wrong Hello,I would like help because I cannot run this script in ssh (file transfer). Code: <script type="text/javascript"> var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"] function showLocalTime(container, servermode, offsetMinutes, displayversion){ if (!document.getElementById || !document.getElementById(container)) return this.container=document.getElementById(container) this.displayversion=displayversion var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>' this.localtime=this.serverdate=new Date(servertimestring) this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time this.updateTime() this.updateContainer() } showLocalTime.prototype.updateTime=function(){ var thisobj=this this.localtime.setSeconds(this.localtime.getSeconds()+1) setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second } showLocalTime.prototype.updateContainer=function(){ var thisobj=this if (this.displayversion=="long") this.container.innerHTML=this.localtime.toLocaleString() else{ var hour=this.localtime.getHours() var minutes=this.localtime.getMinutes() var seconds=this.localtime.getSeconds() var ampm=(hour>=12)? "PM" : "AM" var dayofweek=weekdaystxt[this.localtime.getDay()] this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")" } setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second } function formatField(num, isHour){ if (typeof isHour!="undefined"){ //if this is the hour field var hour=(num>12)? num-12 : num return (hour==0)? 12 : hour } return (num<=9)? "0"+num : num//if this is minute or sec field } </script> Current Server Time:<span id="timecontainer"></span><br /> Current LA Time:<span id="timecontainer2"></span><br /> Current New York Time:<span id="timecontainer3"></span><br /> <script type="text/javascript"> new showLocalTime("timecontainer", "server-asp", 0, "short") new showLocalTime("timecontainer2", "server-asp", -60, "short") new showLocalTime("timecontainer3", "server-asp", 120, "short") </script> HI - I'm creating a golf website and the clients asked to put a "Golf Tip" on the site that could be changed. A Google search led me to your script (copied below) for "Tip of the Day", which seems to be exactly -- almost -- what I need. Can you tell me how to change the font color (for the tips) from gray to White? Also, is it possible to alter the script to make the tips weekly rather than daily? Thanks much, Richard Code: <table border="0" width="100%" bgcolor="#E8E8E8" cellspacing="0" cellpadding="0"> <tr><td width="100%"> <script> <!-- /* Tip of the day script By JavaScript Kit (http://javascriptkit.com) Over 200+ free scripts here! */ var today_obj=new Date() var today_date=today_obj.getDate() var tips=new Array() //Configure the below variable to contain the "header" of the tip var tiptitle='<img src="../../tip.gif"> <b>JavaScript Tip of the day</b><br />' //Configure the below array to hold the 31 possible tips of the month tips[1]='Tip 1 goes here' tips[2]='Tip 2 goes here' tips[3]='Tip 3 goes here' tips[4]='Tip 4 goes here' tips[5]='Tip 5 goes here' tips[6]='Tip 6 goes here' tips[7]='Tip 7 goes here' tips[8]='Tip 8 goes here' tips[9]='Tip 9 goes here' tips[10]='Tip 10 goes here' tips[11]='Tip 11 goes here' tips[12]='Tip 12 goes here' tips[13]='Tip 13 goes here' tips[14]='Tip 14 goes here' tips[15]='Tip 15 goes here' tips[16]='Tip 16 goes here' tips[17]='Tip 17 goes here' tips[18]='Tip 18 goes here' tips[19]='Tip 19 goes here' tips[20]='Tip 20 goes here' tips[21]='Tip 21 goes here' tips[22]='Tip 22 goes here' tips[23]='Tip 23 goes here' tips[24]='Tip 24 goes here' tips[25]='Tip 25 goes here' tips[26]='Tip 26 goes here' tips[27]='Tip 27 goes here' tips[28]='Tip 28 goes here' tips[29]='Tip 29 goes here' tips[30]='Tip 30 goes here' tips[31]='Tip 31 goes here' document.write(tiptitle) document.write(tips[today_date]) //--> </script> </td></tr></table> <p align="center"><font face="arial" size="-2">This free script provided by</font><br> <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript Kit</a></font></p> Sorry if this isn't JavaScript What would the script be to get something like the image below, when you click the tab, then the picture and headline pops up? Thanks. Hey, I have a forum, and the forum has an rss feed. I want to take the most 10 recent posts from the feed and insert it into my Home page. I have no clue how to do this. At the moment I have been manually entering the posts as you can see here. All the recent posts on the right side of the page are manually entered by me from my forum. Just wondering if anyone could guide me in a direction to do this programmatically. Hi everyone, I just wrote a little noob script and JSL tester says no errors but I think there's some kind of problem.....can you help me fix the problem???? Code: function doattack(baseatk, wepatk, wepcritmax, oppdef, oppdeffactor, oppextradefmax, opphealth, oppname) { var OpponentHealth = opphealth; var OpponentName = oppname; var BaseATK = baseatk; var WeaponATK = wepatk; var WeaponCriticalMax = "100+Math.floor(Math.random()*wepcritmax+1)"; var ActualWeaponATK = "WeaponATK * WeaponCriticalMax / 100"; var OpponentDEF = oppdef; var DEFfactor = oppdeffactor; //defensefactor: used to multiply preoppdef to calculate actualoppdef so more in number the better rmbr that deffactor must be less than 1 var DEFCriticalMax = "100+Math.floor(Math.random()*oppextradefmax+1)"; var PreOpponentDEF = "OpponentDEF * DEFCriticalMax / 100"; var ActualOpponentDEF = "PreOpponentDEF * DEFfactor"; var DamageDone = "BaseATK + ActualWeaponATK"; var OVRDamageDone = "DamageDone * ActualOpponentDEF / 100"; document.write("You just inflicted " + OVRDamageDone + " damage to " + OpponentName + "!" + "<br>"); var NewOpponentHealth = "OpponentHealth - OVRDamageDone"; if (NewOpponentHealth < 0) { document.write(OpponentName + " is dead!" + "<br>"); break; } else { doattack(BaseATK, WeaponATK, WeaponCriticalMax, OpponentDEF, DEFfactor, DEFCriticalMax, NewOpponentHealth, OpponentName); } } doattack(5, 50, 25, 6, 0.22, 10, 200, RedBabyDragon); GREAT THANKS hi, can any tell me that which script they are using?? and plz if u have share it Thanx http://www.nation4all.org/mf/ regards Fawad |