Jump to content

Rachit Shah

Members
  • Posts

    30
  • Joined

  • Last visited

Posts posted by Rachit Shah

  1. You can put your javascript in a file instead of putting it inline.the js file has the javascript that otherwise you would use inline.Code 1:

    <script language=javascript>alert("rachit");</script>

    Now make a file calles scr.js in which you would put this entry

    alert("rachit");
    Code 2:
    <script language=javascript src=./scr.js></script>

    Code 2 will give same effect as Code 1

  2. I think all codes are equivalent.Internally javascript would take same time to execute the functions in all 4 cases.One thing is that line of the code should be as small as possible.Unnessesarily putting .onclick method would cause an extra line to be parsed by the browser. That may delay the loading with a fraction of second. This is overhead because you can eliminate this by associating functions in the tags definition.element.onclick=fun() would be internally same as < onclick=fun()>I suggest it would be better to associate functions in Tags instead of defining in the window.onload function.

  3. Plz remove submit button, otherwise it will try to submit the form to the url specified in action attribute.I have replaced it with button

    <html><head><title>Military Web Portal</title></head><script type="text/javascript">var username1 = "ryan"var password1 = "ryanpassword"var username2 = "john"var password2 = "johnpassword"var username3 = "tim"var password3 = "timpassword"function accessValidation(){var tempName=document.getElementsByName('txtUsername').item(0).value;var tempPassword = document.getElementsByName('txtPassword').item(0).value;if(tempName == username1 && tempPassword == password1){document.location='http://www.google.com';}else if(tempName == username2 && tempPassword == password2){alert("User 2 access");}else if(tempName == username3 && tempPassword == password3){alert("User 3 access");}else {alert("Please enter the correct username and password");}document.location='http://www.google.com';}</script><body><table border="1" width="100%" id="table1" height="469"><tr><td height="110"><img border="0" src="logo.png" width="892" height="105"></td></tr><tr><td align="left" valign="top"><form><p>Username: <input type="text" name="txtUsername" size="20"></p><p>Password: <input type="password" name="txtPassword" size="20"></p><p>[b][color="blue"]<input type="button" value="Login" name="B1" onclick = "accessValidation()">[/color][/b]<input type="reset" value="Reset" name="B2"></p></form></td></tr></table></body></html>

  4. U can use <div> for this. Check the example.

    <html>	<head>  <script language = "Javascript"> 	 <!-- 	 // SHOW MENU 	 function showTipBox(layerName,imgName){ 	 img = getImage(imgName); 	 TipBoxTop = getImagePageTop(img); // TIP BOX TOP POSITION 	 TipBoxLeft =  getImagePageLeft(img); // TIP BOX LEFT POSITION 	 if (NS4 || IE4) { 	 if (timeOn != null) { 	 clearTimeout(timeOn) 	 hideLayer(onLayer) 	 } 	 if (NS4 || IE4) { 	 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerVis+'"'); 	 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top="'+TipBoxTop+'"'); 	 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left="'+TipBoxLeft+'"'); 	 }  	 onLayer = layerName 	 } 	 } 	  	 window.onerror = null; 	 var bName = navigator.appName; 	 var bVer = parseInt(navigator.appVersion); 	 var NS4 = (bName == "Netscape" && bVer >= 4); 	 var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4); 	 var NS3 = (bName == "Netscape" && bVer < 4); 	 var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4); 	 var menuActive = 0 	 var menuOn = 0 	 var onLayer 	 var timeOn = null // LAYER SWITCHING CODE 	 if (NS4 || IE4) { 	 if (navigator.appName == "Netscape"){ 	 layerStyleRef="layer."; 	 layerRef="document.layers"; 	 styleSwitch=""; 	 layerVis="show"; 	 layerHid="hide"; 	 }else 	 { 	 layerStyleRef="layer.style."; 	 layerRef="document.all"; 	 styleSwitch=".style"; 	 layerVis="visible"; 	 layerHid="hidden"; 	 } 	 }// HIDE MENU 	 function hideLayer(layerName){ 	 if (menuActive == 0) { 	 if (NS4 || IE4) { 	 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerHid+'"'); 	 } 	 } 	 }// TIMER FOR TIP BOX MOUSE OUT 	 function linkTimer() { 	 timeOn = setTimeout("btnOut()",500) 	 }// MOUSE OUT 	 function btnOut(layerName) { 	 if (menuActive == 0) { 	 hideLayer(onLayer) 	 } 	 }// GET IMAGE  	 function getImage(name) { 	 if (NS4) { 	 return findImage(name, document); 	 } 	 if (IE4) 	 return eval('document.all.' + name); 	 return null; 	 } 	  	 function findImage(name, doc) { 	 var i, img; 	 for (i = 0; i < doc.images.length; i++) 	 if (doc.images[i].name == name) 	 return doc.images[i]; 	 for (i = 0; i < doc.layers.length; i++) 	 if ((img = findImage(name, doc.layers[i].document)) != null) { 	 img.container = doc.layers[i]; 	 return img; 	 } 	 return null; 	 } 	  	 function getImagePageLeft(img) { 	 var x, obj; 	 if (NS4) { 	 if (img.container != null) 	 return img.container.pageX + img.x; 	 else 	 return img.x; 	 } 	 if (IE4) { 	 x = 0; 	 obj = img; 	 while (obj.offsetParent != null) { 	 x += obj.offsetLeft; 	 obj = obj.offsetParent; 	 } 	 x += obj.offsetLeft; 	 return x; 	 } 	 return -1; 	 } 	  	 function getImagePageTop(img) { 	 var y, obj; 	 if (NS4) { 	 if (img.container != null) 	 return img.container.pageY + img.y; 	 else 	 return img.y; 	 } 	 if (IE4) { 	 y = 0; 	 obj = img; 	 while (obj.offsetParent != null) { 	 y += obj.offsetTop; 	 obj = obj.offsetParent; 	 } 	 y += obj.offsetTop; 	 return y; 	 } 	 return -1; 	 } 	   // -->  </script>	</head>	<body>  <a href="#" onMouseOut="linkTimer()" onMouseOver="showTipBox('Delete','imgDel')"><font class="font" color="#CC6600" face="Arial, Helvetica, sans-serif" size="2">Tip   Box</font></a> <img src="/images/shim.gif" width="5" height="5" border="0" name="imgDel">  <div id=Delete style="position: absolute; width: 228px; height: 33px; z-index: 1; visibility: hidden">   <table border="0" cellspacing="0" cellpadding="0">  <tr>   <td bgcolor="#990000">   <table border=0 cellpadding="4" cellspacing="1"><tr>  <td bgcolor="#FFFFFF"><img src="/images/shim.gif" width="2" height="2" border="0"><font face="Arial, Helvetica, sans-serif" size="2" color="#000066">This is a text link tip box : </font> <font face="Arial, Helvetica, sans-serif" size="2">This<br> function should be used for ..... ....... ........ </font></td>  </tr>  </table></td>  </tr>  </table>	</div>	</body></html>

  5. Does it mean that U want to display all Tags present in the same web page.OrIt means that U want to display all tags client browser can support.

  6. Thats not necesssary at all. Its working. Check this. I think Its information for website downloaders like 'website copier' which downloads sites automatically.

    <html><head><meta http-equiv="Content-Language" content="en-us"></head><script type="text/javascript"><!--function ValidateAuthentication() {var UserName=document.getElementsByName('UserName').item(0).value;var Password=document.getElementsByName('Password').item(0).value;if(UserName == 'rachit' && Password == 'password1'){alert('Successfully Authenticated - Redirecting to google.com');document.location='http://www.google.com';}else{alert('Failed to Authenticate - Put the code for error msg here');}}//--></script> <body><form ><table border="0" width="50%" id="table1" align=center><tr><td>User Name</td><td><input type="text" name="UserName" size="20" value='rachit'></td></tr><tr><td>Password</td><td><input type="text" name="Password" size="20" value='password1'></td></tr></table><p align="center"><input type="button" value="Submit" name="B1" onclick="ValidateAuthentication()"><input type="reset" value="Reset" name="B2"></p></form><table border="0" width="50%" id="table2" align=center><tr><td>Another input with same name</td><td><input type="text" name="UserName" size="20"></td></tr></table></body></html>

  7. When I am using document.body.innerHTML, I am getting<input type="button" onclick="writeIt()" value="Write">I dont know where the / has gone.Do anyone know How can I retrieve exact source line.(i.e with / in the tag source)

    <html><head><script id='script1' name='script1' type="text/javascript">function writeIt () {var x= "<script>" + window.document.scripts(0).text;x = x + "</script";x = x + ">";alert(x);alert(document.body.innerHTML);}</script></head><body><input type="button" onclick="writeIt()" value="Write"/></body></html>
  8. Check this. Just click submit. Based on authentication details, it will redirect to google. Key is document.location='http://www.google.com';

    <html><head><meta http-equiv="Content-Language" content="en-us"></head><script type="text/javascript"><!--function ValidateAuthentication() {var UserName=document.getElementsByName('UserName').item(0).value;var Password=document.getElementsByName('Password').item(0).value;if(UserName == 'rachit' && Password == 'password1'){alert('Successfully Authenticated - Redirecting to google.com');document.location='http://www.google.com';}else{alert('Failed to Authenticate - Put the code for error msg here');}}//--></script> <body><form method="POST" action="--WEBBOT-SELF--"><!--webbot bot="SaveResults" U-File="C:\Documents and Settings\161470\Desktop\_private\form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><table border="0" width="50%" id="table1" align=center><tr><td>User Name</td><td><input type="text" name="UserName" size="20" value='rachit'></td></tr><tr><td>Password</td><td><input type="text" name="Password" size="20" value='password1'></td></tr></table><p align="center"><input type="button" value="Submit" name="B1" onclick="ValidateAuthentication()"><input type="reset" value="Reset" name="B2"></p></form><table border="0" width="50%" id="table2" align=center><tr><td>Another input with same name</td><td><input type="text" name="UserName" size="20"></td></tr></table></body></html>

  9. Use <div id=myId> inside the cell.Now get div element in javascript using getElementById("myId").use .innerHTML = "<input><img >"If this is not a hint to the solution, I think you should be more clear on the problem.

  10. Hi anybody knows about error bubbling? which is used to prevent users from entering letters to an input field such as telephone box or calculator screen. cheers!
    AlleyCat, Error is also an event in itself.In late 90's Microsoft came up with event bubbling and Netscape with event capturing. Those are differnet approaches for handling events. Netscape 4 supported event capturing but its buggy. So netscape changed to event bubbling. Now all the browsers support event bubbling.In the above code the first input has no event function attached; but still the event is passed to Body tag (which is parent class/parent node). This is event bubbling. The event passes to parent class regardless of whether its handled or not handled at the element level.For the second input it has event function which will be executed first. Then the event will propogate to BODY tag. The same event will fire again. It has fired twice. Once at the element level and second time at parent node level. This clarifies event bubbling. The event is fired at element level and again it will fire on parent class/node/tag. If you cancel event bubbling then the same code would not alert for the first element, and it would alert (element level event) only once. You wont get the body tag's event function executed.Check out this pagehttp://www.quirksmode.org/js/events_order.html
    <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>New Page 1</title><script type='text/javascript'>function doSomething(){alert('this alert comes on bubbled key down event');}function keyme(evt){//var myEvent = (window.event) ? window.event : evt;//myEvent.cancelBubble=true;alert('element event');}//document.write('<input value="">');//document.write('<input onkeydown="keyme(event)" value="">');</script></head><BODY onkeydown="doSomething();">This box does not have element level event <input value="">This box has element level event<input onkeydown="keyme(event)" value=""></body></html>
  11. Thanx for all that you have discussed here in this thread. It cleared a cruicial understanding of how javascript may parse the script.HTML/Javascript is like my hobby/interest.If I come to know something offbeat (advanced technical details) about javascript/HTML then I think I would accumulate advanced knowledge.I would say I have intermediate level understanding in HTML/Javascript. I want to be advanced in this topic and that was the reason I joined this forum. Dont take literal meaning of "offbeat". I dont mean unusual, I mean advanced or tricky.

  12. I was wondering if you could explain what the .item(0).value; part means?I kind of understand that you are accessing the contents of the variable 'UserName', but I am unclear on what the second part is for.ThanksRyan

    You might have more than one elements with same name. Then by accessing document.getElementsByName() is actually an array of elements.Item(0) will represent first element with that name.Item(1) will represent second element with the same name.If there is only one element with that (unique) name, then surely you can use document.getElementsByName().value. I agree with scott. I believe using Id is a good practise.If there are more than one elements with same Id then I think SCOTT has to reconsider his statement!!! ( getElementsbyId().value wont work then). This is silly, but it deserves clarification.I have changed the code and put another input with same name ('UserName'). Still the code will work because of .item(0).value !!!
    <html><head><meta http-equiv="Content-Language" content="en-us"></head><script type="text/javascript"><!--function ValidateAuthentication() {var UserName=document.getElementsByName('UserName').item(0).value;var Password=document.getElementsByName('Password').item(0).value;if(UserName == 'rachit' && Password == 'password1'){ alert('Successfully Authenticated - Put the code for redirection here');}else{ alert('Failed to Authenticate - Put the code for error msg here');}}//--></script> <body><form method="POST" action="--WEBBOT-SELF--"><!--webbot bot="SaveResults" U-File="C:\Documents and Settings\161470\Desktop\_private\form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><table border="0" width="50%" id="table1" align=center><tr> <td>User Name</td> <td><input type="text" name="UserName" size="20"></td></tr><tr> <td>Password</td> <td><input type="text" name="Password" size="20"></td></tr></table><p align="center"><input type="button" value="Submit" name="B1" onclick="ValidateAuthentication()"><input type="reset" value="Reset" name="B2"></p></form><table border="0" width="50%" id="table2" align=center><tr> <td>Another input with same name</td> <td><input type="text" name="UserName" size="20"></td></tr></table></body></html>

  13. Hi Ryan,

    I first have to let you know that javascript is not an advisable way to authorize user access via username and password. Since javascript is a client site scripting language, all the source of the functions and everything you need to hack it is there - so a username and password validated/authorized solely through javascript is like leaving your door wide open when you leave on vacation and asking no one to go in.
    I think skemcin is right. But still if you want to use client side javascript, Find the code below. End-user never know such kind of validations, and he wont check source for the script, so this may work when the content of the pages is not sensitive.You can user same code on server side (Using ASP) and the source is secure. In the browser of the user, it wont show the script ( and hardcoded password, username)Use username = rachit and password = password1
    <html><head><meta http-equiv="Content-Language" content="en-us"></head><script type="text/javascript"><!--function ValidateAuthentication()	{	var UserName=document.getElementsByName('UserName').item(0).value;	var Password=document.getElementsByName('Password').item(0).value;	if(UserName == 'rachit' && Password == 'password1')	{  alert('Successfully Authenticated - Put the code for redirection here');	}	else	{  alert('Failed to Authenticate - Put the code for error msg here');	}}//--></script> <body><form method="POST" action="--WEBBOT-SELF--">	<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><table border="0" width="50%" id="table1" align=center>	<tr>  <td>User Name</td>  <td><input type="text" name="UserName" size="20"></td>	</tr>	<tr>  <td>Password</td>  <td><input type="text" name="Password" size="20"></td>	</tr></table>	<p align="center"><input type="button" value="Submit" name="B1" onclick="ValidateAuthentication()"><input type="reset" value="Reset" name="B2"></p></form></body></html>

  14. I need some insight regarding below code.In the below code...If I change <\/script> to </script> its giving error.If I change <\/head> to </head> its not giving error. Why? Why? Why?Here is the working code. Its working fine. The above scenario is visible here. I have put it in red.

    <html><head><script id='script1' name='script1' type="text/javascript">function writeIt () {var x="";x = x + "<html>\n<head>\n";x= x + "<script>" + window.document.scripts(0).text;x = x + "<\/script>\n";x = x + "</head>\n<body>\n";x = x + document.body.innerHTML;x = x + "\n</body>\n</html>";alert(x);document.close(); // or document.open();document.write(x);}</script></head><body><input type="button" onclick="writeIt()" value="Write"/>rachit</body></html>
    Is this thing Browser specific? I mean Implementation specific?
  15. If I change <\/script> to </script> its giving error.If I change <\/head> to </head> its not giving error. Why? Why? Why?Here is the working code. Its working fine. The above scenario is visible here. I have put it in red.

    <html><head><script id='script1' name='script1' type="text/javascript">function writeIt () {var x="";x = x + "<html>\n<head>\n";x= x + "<script>" + window.document.scripts(0).text;x = x + "<\/script>\n";x = x + "</head>\n<body>\n";x = x + document.body.innerHTML;x = x + "\n</body>\n</html>";alert(x);document.close(); // or document.open();document.write(x);}</script></head><body><input type="button" onclick="writeIt()" value="Write"/>rachit</body></html>
  16. Plz provide exact relationship between the tables.What you have mentioned in subsequent replies does not clarify the tables and relations.Like lot_status_types is not mentioned anywhere except in the code.I suppose U have to use outer join. Plz paste the code as well table description, I may help you.

  17. I am aware I can use the Insert Select query, but I am curious how to do that when the two tables are in separate databases?

    If you are talking about two databases in the same DMBS environment, then its possible.Like if you have two databases in two different oracle environments, I mean both the database are oracle database; and you want to access the tables of the other database then its possible through dblink. Suppose..Table1 is in database1Table2 is in database2 Log in to database1 and issue query
    select * from table1; //this would work because the table is in same database.

    Now create dblink (in database1) for database2 as dblink_db2issue query

    select * from table2@dblink_db2

    This would fetch the records from table2 of database2 ( despite the fact that you are logged in database1).

×
×
  • Create New...