Jump to content

bibby

Members
  • Posts

    171
  • Joined

  • Last visited

    Never

Posts posted by bibby

  1. I've found it beneficial to unset the display property when "showing". Think of it as "unhiding", especially with table related tags. Firefox supports display properties "table-row" where IE does not. For those cases:

     

    style.display = "none"; // to hide

    style.display = ""; // to unhide

     

    This works with everything.

  2. When using inline javascript with images, as well as with other elements, the keyword this can be used.

     

    <img src="some.jpg" onmouseover="this.src='someother.jpg'" onmouseout="this.src='some.jpg'" />

     

    I much rather prefer to teach the images how to rollover themselves. If you continue the naming convention 'menu#on.jpg' and '2menu#on.jpg', you could use something like this:

     

    // anonymous function leaves no mess, 
    // just run it AFTER the images are created
    (function()
    {
    //gather all images
    var img,imgs=document.getElementsByTagName('img');
    for(var i=0; i< imgs.length; i++)
    {
    	img=imgs[i];
    
    	// use only those that match menu#on.jpg
    	if(img.src.match(/menu\don\.jpg/)==null)
    		continue;
    
    	// assign the alternate source as a member var
    	img.over_img = (function()
    	{
    		var parts = img.src.split(/\//).reverse();
    		parts[0]="2"+parts[0];
    		return parts.reverse().join('/');
    	})();
    
    	// retain the original src
    	img.orig_img = img.src;
    
    	// use the alternate on hover
    	img.onmouseover = function()
    	{
    		this.src = this.over_img;
    	}
    
    	// return to normal when out
    	img.onmouseout = function()
    	{
    		this.src = this.orig_img;
    	}
    }
    })();

  3. .style.height is giving back a string.  Something like "20px";

     

    The unresponsive behavior is a loop that never ends, so cover your bases.

    Also note that this doesn't give an animation effect, so you might as well just set it to 40 outright. Animation is a different topic.

     

    function expand_box()
    {	
    var elm = document.getElementById("pop1"); // save this reference for easier coding
    var old = parseInt( elm.style.height , 10); // make sure it's a number (base 10).
    if(isNaN(old)) // doubly make sure
       old = 0;
    
    while(old<=40)
    {
    	elm.style.height=old++;
    
    	// plus-plus changes "old"'s value.
    	// your loop, even if 10 would remain at 10 forever
    }
    }
    

     

     

     

  4. ah, then that'd be a Range.

     

    Here are some fns that came from quirksmode

    function getcaret(elm) 
    {
    var caret = 0;
    // IE Support
    if (document.selection) 
    {
    	elm.focus ();
    	var sel = document.selection.createRange ();
    	sel.moveStart ('character', -elm.value.length);
    	caret = Sel.text.length;
    }
    
    // Firefox support
    else if (elm.selectionStart || elm.selectionStart == '0')
    	caret = elm.selectionStart;
    
    return (caret);
    };
    
    function setcaret(elm, pos)
    {
    if(elm.setSelectionRange)
    {
    	elm.focus();
    	elm.setSelectionRange(pos,pos);
    }
    else if (elm.createTextRange) {
    	var range = elm.createTextRange();
    	range.collapse(true);
    	range.moveEnd('character', pos);
    	range.moveStart('character', pos);
    	range.select();
    }
    };

     

    So your textarea might look like this to set the caret at the start when clicked.

     

    <textarea name="foo" onfocus="setcaret(this,0)">asdf asdf asdf asdf </textarea>

  5. with comments

     

    img_num = 0;
    inames = new Array("monkey_01.gif", "monkey_02.gif", "monkey_03.gif");
    imgs =new Array();
    tot = imgs.length;   //  tot is 0 , you just made imgs above.
    for(i=0;i<tot;i++)   //  never runs. tot is 0.  I think you want inames.length
    {
    imgs[i] = new Image();
    imgs[i].src = inames[i];
    }
    

     

    ..should be fine after that.

  6. yup.

    Though if you want javascript to do this, it would happen when the user tries to submit, and wouldn't be allowed to if there is an error.

     

    First,  stop the form from submitting like normal by overriding it's onsubmit.

     

    <form name="foo" onsubmit="checkForm(); return false;">
    <input type="text" size="8" name="num" />
    <input type="submit" />
    </form>

     

    Next, you can make the checkForm function that will validate the input and submit the form itself or not.

     

    <script language="javascript" type="text/javascript">
    function checkForm()
    {
    var v = document.foo.num.value;
    if( v.match('([^0-9]+)') != null || v=='')
    {
    	alert('value must be a number');
    	return false;
    }
    else
    {
    	document.foo.submit();
    }
    }
    </script>

     

    String.match takes a regular expression, and makes an array of matching text. In this case, v.match is looking for "anything not whole number". It's up to you to allow negative or floating point numbers: match('([^0-9\.-]+)') if you do. If no match is found, it returns null , meaning it is numeric and can be submitted.

     

    RegEx is preferable (to me) over parseInt or (+v) , because .value is a string no matter what its contents. Hope this helps.

  7. ought to do it

    //js
    function checkAll()
    {
         // get all the inputs
    var cb = document.getElementsByTagName('input');
    
         // loop through them
    for(var i=0;i<cb.length;i++)
    {
                 // looking only for checkboxes
    	if(cb[i].type=='checkbox')
                    {
                          // check it
    		cb[i].checked=true;
                     }
    }
    }
    
    
    //html
    <input type="checkbox" name="checkAll" onclick="checkAll()" />

  8. You should really keep quotes around your attributes.

    If the text contained a space, you'd be sunk.

     

    Other than that, text inputs posting as part of an array should work fine.

    such as..

    <?
    print_r($_POST);
    ?>
    <form method="post">
    <input type="text" name="qty[]" /><br />
    <input type="text" name="qty[]" /><br />
    <input type="text" name="qty[]" /><br />
    <input type="submit" />
    </form>
    

  9. Undefined variable is a Notice , yes?

    Not a Fatal Error, not a Warning.

     

    IMO, PHP's error reporting level is too high.

    Undefined variables could be checked all the time in normal situations, and shouldn't really be sent to the screen unless you really intend it to.

     

    Dig my reply to this post, where the problem may have been that the level was too low.

    http://www.phpfreaks.com/forums/index.php/topic,170596.0.html

     

    error_reporting(7) (same as error_reporting(E_ERROR | E_WARNING | E_PARSE) )

    is a good level for reporting true problems, and not silly notices

  10. Your code works for me.

    Nothing loads on your page at all?

     

    Perhaps your host doesn't support "something", but I can't see what it might be..

     

    You might be able to coax some errors from the server by changing php settings first.

    At the start of your page, put

    ini_set('display_errors',TRUE);
    error_reporting(7);
    

     

    If still blank, try increasing the error reporting level. The list of values is here, but 7 is fairly common.

    http://www.php.net/manual/en/function.error-reporting.php

  11. Give your checkboxes the same name and use brackets to make them into an array

     

    You want in your form,

    echo "<input type='checkbox' name='delete[]' value='$file'>";
    

     

    ..and for your handler

    if(is_array($_POST['delete']))
       foreach($_POST['delete'] as $filepath)
            if(file_exists($filepath))
                   unlink($filepath);
            else echo "can't find $filepath <br />\n";
    

     

     

    Here's a whole test page for that.

    <?
    var_dump($_POST);
    ?>
    
    <form method="post">
    <input type="checkbox" name="delete[]" value="1">
    <input type="checkbox" name="delete[]" value="2">
    <input type="checkbox" name="delete[]" value="3">
    <input type="submit">
    </form>
    

  12. I noticed that the script is assuming that register globals.

     

    First test the mail function itself.

    Just after the first mail call , add a line explicitly testing that fxn.

    mail('you@yourdomain.com','Subject Test','Body Test','From: foo@test.org');
    

    if that works. mail() is fine.

     

    Now test the variables

    echo "<h1>$EmailAddress ?</h1>";
    

    $EmailAddress was supposed to come from the form. Did it make it?

    If so, you'd see it nice and big. The reason for the question mark is to see something in case $EmailAddress is empty.

     

    Next, try,

    echo "<h1>".$_POST['EmailAddress']." ?</h1>";
    

     

    Did that make a difference?

    If register globals is off, you'll have to use $_POST , $_GET, or $_REQUEST.  (REQUEST == $_GET & $_POST)

     

    To test for those

    var_dump($_POST);
    var_dump($_GET);
    

     

    Use what you find.

    If these are null or flase, it's your form's fault.

     

     

  13. Mateobus,

    The write out function would be imagepng() .

    http://us2.php.net/manual/en/function.imagepng.php

     

    So right where you've left off (or in your loop) ...

     

    // path to save, dir must be 777 , you are web-user not "you"
    $captcha_path = '/home/you/www/project/path/captcha/'.
    
    //save the file
    imagepng($captcha , $captcha_path.'filename.png');
    

     

    imagepng() also be used with headers (see php.net examples) to send an image like this..

    <img src="captcha.php">
    

    , but there can be no other output.

     

    If you do decide to premake images (and I don't think that you should) , get friendly also with opendir() , readdir() , and the holy file_exists() .

  14. I think you have your roles mixed up.

     

    javascript != ajax  , essentially.

     

    I think that you may have gone down the road of AJAX because you want to turn the page without reloading? If you are, here are duty assignments:

     

     

    The database has the page content,

    PHP identifies the page and returns the page content

    Javascript will handle keeping track of the current page. There's nothing ajax'y about your page2 function at all.

    the AJAX role in this business is to ask for and display new content.

     

     

    If you are following this link ,  index.php?page=2

    The business of getting the page 2 content to the page is between php & mysql.

    Javascript can decide through functions whether or not to call ajax.

    Ajax could then ask php&mysql for page1 content if you told it to.

     

     

  15. matthewst, your php and mysql look just fine as your tests show. To have this dynamic processing both on the server side, and the client side without a refresh,  you ought to lookup and realy get to know javascript.

     

    words to search for are javascript, events, onclick, ajax, xmlhttp;

     

    There is a thread with a lot of good code I participated in today that's worth a peek. http://www.phpfreaks.com/forums/index.php/topic,148418.0.html

     

    Javascript and the DOM have broken down the elements on a page to the point where one can query the server for a single value (like player1's HP) and replacing the content of an html element -> in this case perhaps, the html element that contains within it the current player1 HP (span, p, div).

  16. Hi bsprogs,

    I've recently solved this problem myself [and help from dav the gook]. You can have ajax return executable javascript, but not with html script tags.

    The magic line in your code is in getLinkCodes()

    obj.innerHTML = XMLHttpRequestObject.responseText;

     

    Don't consider the content of responseText as whole elements, just a plain string.

    We could fork this line, and separate out the parts we are using as replacement html, and executable javascript.

     

    First, I'm going to change the output of linkcodes.php to look like the following. This does not have to be valid syntax because I'm going to parse this string again. I used a triple pipe , '|||' , as a delimiter. I'm also putting the javascript at the end since you may not use it all of the time.

     

    <textarea rows="15" cols="100" id="link_codes" name="link_codes" style="padding: 2px;"></textarea>|||alert('testing');
    

     

     

    So now responseText can be split (javascript equivilent to php's explode() ). If we find something behind the delimiter, it gets eval()'d. A good thing to do is make all of your necessary functions available early on, and then have ajax return minimal instructions.

     

    
    function getLinkCodes(datasource, divID)
    {
    if (XMLHttpRequestObject) 
            {
    	var obj = document.getElementById(divID);
    	obj.innerHTML = "Loading...";
    	XMLHttpRequestObject.open("GET", datasource);
    
    	XMLHttpRequestObject.onreadystatechange = function()
                   {
    		if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                            {
                                   var rtext =  XMLHttpRequestObject.responseText.toString(); //just in case
                                   var components  = rtext.split('|||');
                                   
                                    //set html
                                   	obj.innerHTML = XMLHttpRequestObject.components[0];
    
                                     //exec js !
                                   if (typeof(components[1])!='undefined'){ eval(components[1];};
    		}
    	}
    	XMLHttpRequestObject.send(null);
    }
    }
    
    

     

     

    To take it to the next level (based on the title of this post), the second half of your return string (right side of the |||) can be whole javascripts and have php generated value.

    linkcodes.php

    <?
    $html ='<textarea rows="15" cols="100" id="link_codes" name="link_codes" style="padding: 2px;"></textarea>';
    $js = ' alert("your session has '.sizeof($_SESSION).' variables");' ;
    
    echo $html . '|||'. $js; 
    ?>
    
    ?>
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.