Jump to content

Pain

Members
  • Posts

    178
  • Joined

  • Last visited

Posts posted by Pain

  1. Hi guys. Im trying to implement a javascript validation where if a customer leaves a blank select option, then an error pops out. I was able to display one error at a time even though all fields are blank. 

    function validateSurvey2()
    {
     
      var err1 = document.getElementById('err1');
      var err2 = document.getElementById('err2');
      var err3 = document.getElementById('err3');
      var err4 = document.getElementById('err4');
     
      var question1 = document.survey.q1;
      var question2 = document.survey.q2;
      var question3 = document.survey.q3;
      var question4 = document.survey.q4;
     
      if(question1.selectedIndex === 0) {
        err1.style.display="inline";
        question1.focus();
        return false;
      }
     
      else {
        err1.style.display="none";
      }
      if(question2.selectedIndex === 0) {
        err2.style.display="inline";
        question2.focus();
        return false;
       
      }
      else {
        err2.style.display="none";
      }
      if(question3.selectedIndex === 0) {
        err3.style.display="inline";
        question3.focus();
        return false;
      }
      else {
        err3.style.display="none";
      }
      if(question4.selectedIndex === 0) {
        err4.style.display="inline";
        question4.focus();
        return false;
      }
      else {
        err4.style.display="none";
      }
     
     
    }
    
    

    This is probably because the script stops after the first 'return false'...

     

    I want every block of IF executed. 

     

    thanks in advance for any help:)

  2. Hi.I want to get the value (or rather text) of selected option.

    function val() {
     
    var num1 = parseInt(document.getElementById("over_16").value);
    var mytrip = document.getElementById('privated').text;
        
        if(mytrip = 'Lake District') {
          document.getElementById("sum").value = num1 * 55;
     
        }
        
        else if(mytrip = 'Private Trip') {
          document.getElementById("sum").value = num1 * 120;
     
        }
     
        }
     
    
    
    

    Somehow i always get the value which is in the first IF statement. It doesnt matter which one is selected, the value will be the one in the first IF statement.

    if(mytrip = 'Lake District') {
          document.getElementById("sum").value = num1 * 55;
     
        }

    and this is my <select> code

    <select name="trip" style="width: 205px" id="privated">
    <option value="Lake District">Lake District</option>
    <option value="Private Trip">Private Trip</option>
    </select>
    
    

    this is how the function gets activated (another dropdown list)

    switch($available_places[0]) {
    case 1:
    $select = '<select id="over_16" name="over_16" style="width: 206px" required="required" onchange="val()"><option>0</option><option>1</option></select>';
    break;
     
    case 0:
    $select = '<select id="over_16" name="over_16" style="width: 206px" required="required" onchange="val()"><option disabled="disabled">0 places left</option></select>';
    break;
    }
    
    

    what could be the problem here?

  3. Hi.

     

    I want to get an element by id with a value, instead of just id.

     

    <input name="select_one" type="radio"  value="METRO" id="radio" onClick="if(this.checked) document.getElementById('service14').disabled=true;" />
     
    so here instead of disabling an element with id 'service14', i would like to disable an element with that id AND a value (let's say 'abc').
     
    What do i need to change in that line?
     
    Thank you!
     
  4. Hi. I am trying to make my url look more attractive.

     

    So far i have managed myweb.com/job.php?ref=333 to make look myweb.com/job?ref=333

     

    How can i shorten it further by making myweb.com/job/333

     

    I have this code

     

    
    
    RewriteBase /
     
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php
     
     
     
     
     
    RewriteRule ^job-([0-9]+)\.php$ job.php?ref=$1
     
    RewriteRule ^job/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ job.php?ref=$2
     
    RewriteRule ^([a-zA-Z0-9_-]+)$ job.php?ref=$1
    RewriteRule ^([a-zA-Z0-9_-]+)/$ job.php?ref=$1
     
    
    
    
    

     

    thanks for your help:)

     

  5. Im having trouble understanding the point of assigning certain values to certain variables within the class.

     

    Say we have

     

    <?php
     
    class MyClass {
    public $variable;
     
    public function getVariable($variable) {
    $this->variable = $variable; 
    }
     
    }
    

    Why assign the value of $variable to $this->variable instead of simply using $variable which has been passed as an argument?

     

    Thanks:)

     

  6. Thanks for the help guys. The thing i did not understand here was this line:

    function __autoload($classname) {
    

    I didn't get how does the PHP now what the $classname is. I found a tutorial which explained that instantiating a class tells the __autoload which class is an argument.

    $validator = new Validator;
    

    am i correct?

  7. Hi.

     

    I am trying to learn to autoload classes, but im having some problems understanding the implementation and the usefulness of this.

     

     

    index.php

    
    
    $classname = 'class.validator';
     
    function __autoload($classname) {
    $filename = $classname . '.php';
    require_once($filename);
    }
     
    $validator = new Validator;
     
    

    class.validator.php

    
    
    <?php
     
    class Validator {
     
    function validateSomething() {
    ...
    }
     
    }
    ?>
    

    This code does not work even though i followed a tutorial. And even if it would work, then i fail to see how this is better than:

    
    
    <?php
    require_once('class.validator.php');
     
    $validator = new Validator;
     
    ?>
    
  8. I am trying to retrieve multiple values from the db and then display them, however the way i'm doing it seems wrong. 

    
    
    <?php
    $query_members = "SELECT username, id FROM members LIMIT 10";
    $result = $db->run($query_members);
     
    $i = 0;
    foreach($result as $username[$i]){
    echo "<br />" . implode(" ", $username[$i]);
    $i++;
    }
    ?>
    

    This way one variable holds two values - username and id. How can i assign those values to two different variables?

     

    Thanks!

  9. Hello there.

     

    I am using the PDO wrapper class:

     

    http://www.imavex.com/php-pdo-wrapper-class/

     

    The problem:

    When i'm trying to retrieve data from the db and then echo it out - the result i get is "Array" and not the actual value.

     

    What is wrong here, how can i retrieve actual value?

     

    The way i'm trying to retrieve and display values:

     
    $results = $db->select("mytable");
    echo $results;
     
    
  10. Hello.

     

    I am in need of some help:)

     

     

    I know how to set up an interval, but now i need to clear it. So i thought u guys could help me out:)

     

    I set my interval like this

     

    setInterval(function(){
    loadUpdateLevelPercentage();
    }, 10000);
    

     

    How can i clear it after 40 seconds?

  11. Hi.

     

    I am trying to call a jquery function inside a conditional statement:

     

    [code

     

    <!doctype html>

    <html>

    <head><title>Home</title>

    <meta charset="UTF-8" />

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>

    <link rel="stylesheet" href="style.css">

    <script>

    function loadSolded()

    {

    $(".soldiers").css("background-image", "url('images/icon_soldier_gas_recruiting.png')");

    }

    </script>

    </head>

    <body>

    <?php

     

    $lol = 1;

     

    if($lol == 2)

    {

    ?><div class="soldiers"></div><?php

    }

    else

    {

    ?>

    <div class="soldiers"></div>

    <script>

    loadSolded();

    </script>

    <?php

    }

    ?>

    </body>

    </html>

    [/code]

     

    But it does not work this way. What am I doing wrong here?

  12. Hello.

     

    I am trying to create time in the future.

    <?php
    
    $time_in_minutes = (round($time / 60));
    $future_time = date("H:i:s",time() + 60 * $time_in_minutes);
    
    ?>
    

     

    It all works. I get something like "15:58:28". Now if i want to insert this record into the database, which type should i pick? DATETIME or TIMESTAMP?

     

    Note that i want to check whether the current time has now passed the future time.

     

    Thanks:)

  13. Hi there. I have a question regarding jQuery remove() method.

     

    I have a lot of stuff being retrieved with ajax (basically every 10 seconds) so the browser eventually starts slowing down. I want to somehow remove the old elements before i retrieve new ones. Would remove() help? Does it completely remove the element?

  14. i've tried

    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    

    but nothing has changed..

  15. Hi.

     

    I have a very common problem, IE caches stuff, so in order to see new things come up i must reload all page.

     

    
    function mountOne()
    {
    
    var myurl = 'mount_shotgun.php';
    myRand = parseInt(Math.random()*99999999); // cache buster
    
    var xmlhttp2;
    if (window.XMLHttpRequest)
    {
    	xmlhttp2 = new XMLHttpRequest;
    }
    
    xmlhttp2.onreadystatechange = function()
    {
    	if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200)
    	{
    		document.getElementById("retrieve").innerHTML=xmlhttp2.responseText;
    	}
    }
    
    
    $('#inventory_item1').css("background-image", "url('images/shotgun.png')");
    
    xmlhttp2.open("GET", myurl + "?rand=" + myRand, true);
    
       xmlhttp2.send();
    
    
    
    }
    

     

    My attempt to bust it using a random token was unsuccessfull

     

    var myurl = 'mount_shotgun.php';
    myRand = parseInt(Math.random()*99999999); // cache buster
    

     

    I would gladly appreciate any kind of help. Thank you.

  16. Not sure if it is a good place to ask, but I'll do it anyway.

     

    if i have a following query:

     

    $query2 = mysql_query("SELECT * FROM testas WHERE username = '$username');

     

    How do i drop the table by injecting sql?

     

    have tried this

    x’; DROP TABLE testas; --

    but nothing happened:D

  17. Hello. I am trying to build a website with many ajax features.

     

    To make the web look more like an app, I am retrieving information with ajax. So i have this code where i can retrieve two different pages with two clicks, but when i retrieve one, and another one on top - i want the first to disappear. However both pages are being loaded. Is there any jQuery method that could effectively hide the first loaded page.

     

    These are two functions that can load pages.

    // first function to load military.php
    function loadMilitary()
    {
    var xmlhttp2;
    if (window.XMLHttpRequest)
    {
    xmlhttp2 = new XMLHttpRequest;
    }
    
    xmlhttp2.onreadystatechange = function()
    {
    if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200)
    {
    document.getElementById("military_tab").innerHTML=xmlhttp2.responseText;
    }
    }
    xmlhttp2.open("GET","military.php",true);
    xmlhttp2.send();
    }
    
    
    // second function to load hospital.php
    function loadHospital()
    {
    var xmlhttp2;
    if (window.XMLHttpRequest)
    {
    xmlhttp2 = new XMLHttpRequest;
    }
    
    xmlhttp2.onreadystatechange = function()
    {
    if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200)
    {
    document.getElementById("hospital_tab").innerHTML=xmlhttp2.responseText;
    }
    }
    xmlhttp2.open("GET","hospital.php",true);
    xmlhttp2.send();
    }
    

     

    And i load them by using the onclick method

    
    <div class="hospital_tab" onclick="loadHospital()"></div>
    <div class="military_tab" onclick="loadMilitary()"></div>
    

     

    I really need help with this guys, thanks for any hint! Hope you understood what i want.

×
×
  • 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.