Jump to content

jesh

Members
  • Posts

    2,293
  • Joined

  • Last visited

Posts posted by jesh

  1. I don't think you need AJAX for this unless there is some data on the server that you need in order to validate the file. Javascript alone should suffice.What about using the focus and blur events on the inputs?1) Regarding switching the background color: First, set up all required fields so that the background color is yellow. Then, do something like this to make the field change from yellow to white when the user puts focus on the field and back to yellow if s/he leaves the field without typing in any data:

    <input type="test" id="UserName" onfocus="this.style.backgroundColor = 'white';" onblur="validate(this);" />

    function validate(element){	if(element.value == "")	{		element.style.backgroundColor = "yellow";	}}

    2) and 3) I'm not really sure where you're going with this. Should the error message show up before the user even begins entering data into the form? Should it only show up if the user clicks the submit button? Or when focus is given to the field? If it is when focus is given to the field, you could do something like this:

    <span id="UserNameError" style="display: none;">This field is required.</span><input type="test" class="required" id="UserName" onfocus="enteredField(this);" onblur="validate(this);" />

    function enteredField(element){	if(element.className == "required")	{		element.style.backgroundColor = "white";		var span = document.getElementById(element.id + "Error");		if(span)		{			 span.style.display = "inline";		}	}}function validate(element){	if(element.value == "")	{		element.style.backgroundColor = "yellow";		var span = document.getElementById(element.id + "Error");		if(span)		{			 span.style.display = "none";		}	}}

  2. from that site u gave me above...Cookies were invented to solve this problem. There are other ways to solve it, but cookies are easy to maintain and very versatile.whats the other method, just curios
    You can use cookie-less Sessions. This is where a unique identifier is encoded into the URL of the request so that the server can associate the visitor with that visitor's session. Depending on the implementation, the URLs can come out pretty ugly:e.g. http://www.mysite.com/3432ec7b66ffa2390af7c73d/index.html
  3. okay solved it. Apparently IE7 doesn't recognize <br style="clear:left"/> everything works fine when I changed it to <div style="clear:left"></div>, man I hate IE
    Yer kidding me. IE7 doesn't support <br style="clear: left;" />? What else are they willy-nilly going to attempt to change?
  4. I don't know what you've tried, so I don't know if you've already seen this, but this page looks pretty helpful:http://www.howtocreate.co.uk/tutorials/javascript/domcssSpecifically, the sections on "Rewriting Stylesheets", "Changing the href", and "Switching stylesheets".
    I tried to post this yesterday but the session timed out. (What's with this site being so slow sometimes???).Anyhow, in addition to the link above, you can check here as well:http://www.quirksmode.org/dom/changess.html
  5. What if you set up your form something like this:

    <form id="LoginForm" onsubmit="return validate();"><span id="UserNameError" style="display: none;">required</span><input type="text" id="UserName" onkeydown="hide('UserNameError');" /><br /><span id="PasswordError" style="display: none;">required</span><input type="password" id="Password" onkeydown="hide('PasswordError');" /><input type="submit" value="submit" /></form>

    Then had javascript like this:

    function hide(elementID){	var element = document.getElementById(elementID);	if(element)	{		element.style.display = "none";	}}function validate(){	var isValid = true;	if(document.getElementById("UserName").value == "")	{		document.getElementById("UserNameError").style.display = "inline";		isValid = false;	}	if(document.getElementById("Password").value == "")	{		document.getElementById("PasswordError").style.display = "inline";		isValid = false;	}	return isValid;}

  6. You typically create one user so that your webserver can connect to the database. You don't need to create a separate database user for each user of your website. You only need the one user for the webserver.

  7. I've never used thead or tfoot at all, I just haven't seen a reason to use them. There might be a semantic reason for using them, but any visual effect I would try to achieve by using them I would just do with CSS.
    I use them sometimes so that I can more easily get at the elements with CSS without setting a class:
    thead th, thead td { font-weight: bold; text-align: center; }

  8. If your iframes had IDs of "LeftFrame" and "RightFrame" like so:

    <html><head><script type="text/javascript">function go(leftURL, rightURL){    // First, let's get references to the iframes on the page.    var leftFrame = document.getElementById("LeftFrame");    var rightFrame = document.getElementById("RightFrame");    // Next, let's see if we found the LeftFrame    if(leftFrame)    {        // We found it, let's set the src for the frame (so the page will load)        leftFrame.src = leftURL;    }    // Next, let's see if we found the RightFrame    if(rightFrame)    {        // We found it, let's set the src for this frame (so the page will load)        rightFrame.src = rightURL;    }}</script></head><body><iframe id="LeftFrame"></iframe><iframe id="RightFrame"></iframe><a href="events.html" onclick="go('events.html', 'calendar.html'); return false;">Calendar</a></body></html>

  9. Try doing a match for anything that isn't a letter:

    var regex = /[^a-zA-Z]/g;if(document.asform.value.match(regex)){	alert("Please enter only letters.");	document.asform.author.value="";	document.asform.author.focus();	return false;}else{	return true;}

  10. All of the links are relative to whichever folder the HTML file is in because, I'm assuming, you are creating the links in the javascript with something like this:

    var link = document.createElement("a");link.href = "somepage.html";

    So, when you are in the root directory and you create a link on your page, it'll link to "somepage.html". When you are in a sub-directory, say, "images/", the link will link to "somepage.html" which will be in the "images/" directory.To get around this, you can make all of your links relative to the root directory like this:

    var link = document.createElement("a");link.href = "/somepage.html";

    Notice the forward slash at the beginning. This tells the browser/webserver that all links should be relative to the root directory. Then, no matter from which directory your HTML file calls the javascript, all the links will be relative to the root directory.

  11. If there is a sulution to this, than I will be very gratfull for it. Once again, thanks!
    If javascript is enabled in the browser, this'll work:
    <a href="#" onclick="return false;">Clicking on this does nothing.</a>

  12. I don't know anything about:

    netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead');
    But it has been my experience that it is not possible to view any of the details (i.e. dimensions of an image, file size, last modified date) of a file that resides on a client computer using javascript. My guess is that you'll have to allow the file to be uploaded to the server and have your server-side code view the details of the file and then decide whether the file matches your criteria or not.
  13. You generally want to avoid using the same variable (e.g. inherit) for different things in your code. Also, I don't think you need the nested loops. You might try changing it to something like this:

    function setTo(element, fontSize){	// Set the font-size.	element.style.fontSize = fontSize;	// Get all the child nodes for this element.	var children = element.childNodes;	// Loop through all the child nodes, one at a time.	for(var i = 0; i < children.length; i++)	{		// Let's add a check to verify that the node is an 		// element rather than something like a text node.		if(children[i].nodeType == 1)		{			// We found an element in the children array.			// Let's recursively call the setTo function on this			// element.			setTo(children[i], fontSize);		}	}}

  14. First thing I notice is that the "page_request" is declared locally in your ajaxpage function and is inaccessible in your callback function ("loadpage()"). Try creating a global variable called page_request instead:

    var bustcachevar=1var loadedobjects=""var rootdomain="http://"+window.location.hostnamevar bustcacheparameter=""var page_requestfunction ajaxpage(url, containerid){page_request = false....

    Second thing, what exactly is your if statement in the callback function ("loadpage()") trying to do? The logic is that if the readyState is 4 (i.e. "complete") and either the response status is 200 (i.e. "OK") or the URL in the address bar doesn't have "http" in it?I would suggest changing it to:

    if (page_request.readyState == 4){	if(page_request.status == 200)	{		// request came back OK, refresh the content	}	else	{		// there was some type of error.	}}

  15. That's going to all be javascript and CSS.

    <html><head><style>#MyForm { position: absolute; top: 300px; left: 300px; }</style><script>function moveit(){    var form = document.getElementById("MyForm");    var _top = form.offsetTop;    var _left = form.offsetLeft;    form.style.top = (_top + Math.random()*100) + "px";    form.style.left = (_left + Math.random()*100) + "px";}</script><body><form id="MyForm">  <input type="submit" onmouseover="moveit();" value="Submit" /></form></body></html>

    Of course, this example only moves the form down and to the right. But you could introduce another variable (or two) that is randomly 1 or -1 to determine which direction to move the form.Hope this helps.

  16. That only works for Internet Explorer unfortunately. :)
    Hmm, I don't know how to return the caret position in IE, but this works to insert data at the caret position (whatever that may be) in IE and Firefox:
    <html><body><textarea id="myTextarea"></textarea><button onclick="newcontent();">New Content</button><script>function newcontent(){	var textarea = document.getElementById("myTextarea");	if(document.selection) // IE Code	{		textarea.focus();		var range = document.selection.createRange();		range.text = "NEW CONTENT";	}	else  // DOM Code	{		var pos = textarea.selectionStart;		var beginText = textarea.value.substring(0, pos);		var endText = textarea.value.substr(pos);		textarea.value = beginText + "NEW CONTENT" + endText;	}}</script></body></html>

×
×
  • Create New...