...

Hi! I’m Starx

experienced Software Developer. And this is my blog
Start Reading About me
Blog Page
July 11, 2010

check box input size

Question by Kumod

I want to increase the check box size for my following code:

<div id="chatBox">
    <form>
        <input type="checkbox" name="chat" value="LiveChat" />Live Chat<br />
        <input type="checkbox" name="email" value="Email us" />Email Us
    </form> 
</div>

is it possible?

Answer by Starx

Check this

http://www.456bereastreet.com/lab/styling-form-controls-revisited/checkbox/
http://www.webdeveloper.com/forum/showthread.php?t=195533

Read more
July 8, 2010

Find class inside class with jQuery selectors

Question by fearofawhackplanet

I’m trying to do something like the following in jQuery

$('.container').siblings('.outerClass > .innerClass')

where I’m looking for:

<div class="container"></div>

<div class="outerClass">
    <div class="innerClass">
        find me!
    </div>
</div>

I can’t get the syntax right.

Answer by Felix Kling

And another one (but this should work) (assuming you want to get the element with class innerClass):

$('.container').siblings('.outerClass').children('.innerClass')

Answer by Starx

You can also do this to directly select the required elements

$(".outerClass").children(".innerClass").click(function() {
//Do your stuff
});
Read more
July 7, 2010

how to combine these 2 jquery code into one

Question by Jitendra Vyas

Should work same as it’s working independently.

This

(function($) { 
     $(document).ready(function(){
          $('#number1').hide();
        $('.button1').click(function(){
              $('.table1').slideToggle();
        $(this).toggleClass("minus_icon"); 
                return false;
   });
});

})(jQuery);

and this

(function($) { 
     $(document).ready(function(){
          $('#number2').hide();
        $('.button2').click(function(){
              $('.table2').slideToggle();
        $(this).toggleClass("minus_icon"); 
                return false;
   });
});

})(jQuery);

both will be used on same page.

Thanks

Edit: Added after @Felix comment

@Felix – Do you mean like this?

(function($) { 
     $(document).ready(function(){
          $('#number2, #number1').hide();
        $('.button2').click(function(){
              $('.table2').slideToggle();
        $(this).toggleClass("minus_icon"); 
                return false;
   });
});
        $('.button1').click(function(){
              $('.table1').slideToggle();
        $(this).toggleClass("minus_icon");
                return false;
   });
})(jQuery);

Answer by Starx

A sample HTML

<button id="button1" class="btn" div="table1">Table 1</button>
<button id="button2" class="btn" div="table2">Table 2</button>
<div class="myDiv" id="div1"><table><tr><td>Table1</td></tr></table></div>
<div class="myDiv" id="div2"><table><tr><td>Table2</td></tr></table></div>

CSS

  .myDiv { display:none; }

Jquery

 $(document).ready(function(){

    $('.btn').click(function(){
        //identify same class to all your div for example in this case I will define all tables as myDiv
        // doing this will not fix the effect to just two tables
        $(".myDiv").slideUp(); //Hide all divs first

        $('#'+$(this).attr("div")).slideToggle(); //show the required
        $(this).toggleClass("minus_icon");
        return false;
    });
});
Read more

speechbubble tooltip using css and jquery

Read more
July 5, 2010

jQuery conflict with body onload event

Question by Evgeny

I have a strange conflict in my code.

I have a function that called from body onload:

var someGlobalVar=new SpecialType(); 
function OnBodyLoad()
{
  someGlobalVar.Bind();
}

But when I include jQuery 1.4.2 in my project I get an error that someGlobalVar is undefined.
Why is the global variable undefined now, and what ways are there to fix it?

Answer by Kevin

Just a side note.

// DOM Ready
$(document).ready(function() {});

// When the page has completely loaded
<body onload="someFunction()">

Answer by Starx

Why don’t you use jQuery’s load event?

$(window).load(function() {
      functiontoexecute();
});

It is simple, and it is easy.

Read more

how do I delay or control queries?

Question by mathew

I planning to release an Api for public. what I am looking into is since it is free I need to control the usage. there are couple of options in my mind. one is delay number of queries per second. second one is fix queries to certain number per day. but second option seems to do more work on scripting which I am planning to avoid now.

so my question is how can I delay number of queries per second limit to 2 and rest put in Queue.

I am working on php so the same script would be appreciated.

or else any other suggestions welcome

Answer by Starx

You can use php’s sleep function to hold the execution in terms of time.

$query = "....................";

// wait for 10 seconds
sleep(10);

// Then execute
$result = mysql_query($query);

//queue other queries in the same way
Read more

PHP file read not working

Question by Bharanikumar

On a server I have the file some.php. I try to read the contents using file_get_content and fread. Both these don’t read my content.

If I try some other URL like yahoo.com, these functions are reading the contents. Why does this happen?

$my_conetn =  file_get_contents("http://example.com");
echo $my_conetn;

The above snippet is not working.

$handle = fopen($filename, "r");
$contents = fread($handle, 20);
echo $contents;
fclose($handle);

Also the above snippet is not working.

How to check my server? Is there any file read operation locked or not?

edit: I am not sure, but it is only my server file that can’t be read. I can read the other server links. So I contact my hosting provider, then I get back to you guys/gals.

Answer by ThiefMaster

When using file functions to access remote files (paths starting with http:// and similar protocols) it only works if the php.ini setting allow_url_fopen is enabled.
Additionally, you have no influence on the request sent. Using CURL is suggested when dealing with remote files.

If it’s a local file, ensure that you have access to the file – you can check that with is_readable($filename) – and that it’s within your open_basedir restriction if one is set (usually to your document root in shared hosting environments).

Additionally, enable errors when debugging problems:

ini_set('display_errors', 'on');
error_reporting(E_ALL);

Answer by Starx

Try to display your PHP configuration with phpinfo() and see if something is blocking you to access the file.

And first try to access your local file, rather than one hosted?

Check:

allow_url_fopen

display_errors

Have you tried on the local file?

Read more

Including JavaScript and CSS in a page (jQuery)

Question by Nimbuz

I recently came across the includeMany jQuery plugin to include external JavaScript and CSS files into a page. Although it was released in early 2009 there are NO references in blogs or elsewhere. I wonder if it’s usable? What is the experience using it?

Answer by Starx

You can include JavaScript and CSS using the example below. There is no need for any plugins.

To include JavaScript code, do this:

$.getScript("youpathtoscript.js",function() {
            //this script is loaded
});

To include CSS files:

$("<link/>", {
   rel: "stylesheet",
   type: "text/css",
   href: "styles/yourcss.css"
}).appendTo("head");
Read more
July 4, 2010

How to do Php Security check for input fields and input treatment?

Question by Yosef

How to do Php Security check for input user fields and input user treatment(please if you can solve example1+2)?

Example1: check if user insert url or something else:

<label>url: </label>
<input type="text">

Example2: check if user insert html or something else

<label>paste html: </label>
<textarea></textarea>

thanks

Answer by h3xStream

1. For the validation of URLs :

$validUrl = strpos($url, "http://") === 0;
if(!$validUrl) $url = "http://".$url;

When the link is return to the user, use htmlentities().

2. For the validation of HTML code, use a lib like http://htmlpurifier.org/.

<?php
require_once 'htmlpurifier/HTMLPurifier.auto.php';

$purifier = new HTMLPurifier();
$clean_html = $purifier->purify($_GET['dirty_html']);
echo $clean_html;
?>

With the input :

<img src="test.gif" onload="alert('xss')"/>

The result is :

<img src="test.gif" alt="test.gif" />
Read more
July 3, 2010

how to set image width and height 100% from css?

Question by mina

my code-

background:url(images/menu_edu.jpg) no-repeat;

but but only half of image is getting displayed.

Answer by Starx

If you want to display your image in full size, no need to use CSS for this

Dont give height and width attribute to the <img> tag like
<img src="this.jpg" /> it will display in full size

But if you want your <div> to show its background in full size, then is no other option than assigning the exact image dimensions

Read more
...

Please fill the form - I will response as fast as I can!