Graphix 68 ---

You should make 2 functions:

- ShowObject(objectId) - CloseObject(objectId) And two global variables:

var maxHeight = 300;
var curHeight;

ShowObject(objectId) sets a Interval of for example every 20 miliseconds in which he calls itself again. Each time the function gets called it increases the height with 3px. If the maximum height has been reached (for example 300px) it stops the interval. CloseObject(objectId) does exactly the same as ShowObject(objectId) , but decreases the height at each function call until it reaches for example 10px.

To retrieve the object's height you should use the codeline curHeight = document.getElementById(objectId).height Good luck!

~G

Graphix 68 ---

You should do the following:

- Create a function that needs one argument, which is the id of the input.

- The function retrieves the value using document.getElementById(id) and then adds the part of text you want on the end.

- Then you update the value of the input with the one with the text on the end.

- The function should be called using the event onsubmit="return function()" in the <form> tag


A small start:

function addText(id) {
var text = document.getElementById(id).value;

// Here comes the rest of the code...

return true;
}

~G

Graphix 68 ---

Perhaps you should calculate a random number with javascript, between 0 and the amount of different videos you want to display. Then you should use a switch to decide which number corresponds with what source, for example:

var randomNumber = 0; // This you need to decide with a random function
var src = "";
switch (randomNumber) {
case 0 :
src = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/1uwOL4rB-go&hl=nl_NL&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/1uwOL4rB-go&hl=nl_NL&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
break;
}

Then you should update the source into the div:

document.getElementById("myVidDiv").innerHTML = src;

~G

Graphix 68 ---

>> Line 13 - You forgot to add the {} at the else. You should always use an if...else the following:

if (...condition...) {

} else {

}

>> Line 14 - Never use a document.write() in a function you call when the page is already loaded. Use a custom message box or use alert("Message"); >> Line 22 - You should use the event onkeypress="check()" instead of onchange="check()" ~G

Graphix 68 ---

>> Line 4 - <script type="text/javascrip"> needs to be <script type="text/javascript"> ~G

Graphix 68 ---

>> Always put code in code tags:

function Length_TextField_Validator()
{
// Check the length of the value of the teamname and teammanager
if ((addteam.teamname.value.length < 3) || (addteam.teamname.value.length > 20))
{
// alert box message
mesg = "You have entered " + addteam.teamname.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team name.\n"
alert(mesg);
// Place the cursor on the field
addteam.teamname.focus();
// return false to stop user going any further
return (false);
}
else if ((addteam.teamamanger.value.length < 3) || (addteam.teammanager.value.length > 20))
{
mesg = "You have entered " + addteam.teammanager.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team manager\n"
alert(mesg);
// Place the cursor on the field
addteam.teammanager.focus();
// return false to stop user going any further
return (false);
}
else {
// If teamname and teammanager is not null continue processing
return (true);
}
}

The errors in your script:

>> Line 4, 11, 15, 21 - You forgot to add the document. add the beginning. Use: document.addteam.teamname or document.addteam.teammanager >> Line 7,8,17,18 - You forgot to end the line with a ;

>> Line 13, 23,27 - You can just use: return true; or return false; >> Line 15 - teamamanger needs to be teammanager like DavidB mentioned

~G

Graphix 68 ---

Never mind, I searched a bit and found out that C doesn't have a boolean, I changed guessLetter into a int, at which 0 represents false and 1 represents true.

The program is now working correctly, thank you very much for you help!

~G

Graphix 68 ---

Ok, I created a new project -> Console application -> C ->variousprojects.cbp -> GNU GCC Compiler -> Debug & Release ->finish.

Then I created a new file:

New -> file... -> c/c++ source -> C -> hangman.c -> finish

The *void *char errors are now fixed, but now it returns errors regarding the boolean guessedLetter. Did I declare it wrong, not according to the C standard?

The errors:

'bool' undeclared
syntax error before "guessedLetter"
guessedLetter undeclared
true undeclared
false undeclared

~G

Graphix 68 ---

I made a small sample code on how to do this:

<script type="text/javascript">
function changeAction(formid, actionvalue) {
 document.getElementById(formid).action = actionvalue;
}
</script>
<form action="formhandler1.php" id="form1">
<input type="button" onclick="changeAction('form1', 'formhandler2.php')" />
<input type="submit" value="submit" />
</form>
Graphix 68 ---

You should try the following:

- Add an id for every input and form
- Write a global function that checks the value (for example check_email(inputid) or check_name(inputid) )
- Use the event onsubmit() in each form tag. In that event you should call a fuction: onsubmit="return checkform(this.id)" - The function checkform(formid) should return a true if all fields have been entered correctly or false if not

~G

stbuchok commented: Not sure why it was down voted, seems like a good answer to me. +5
Graphix 68 ---

I visited the site, but it doesn't go nuts in any browser (I have all 5 leading browsers (ff, ie, opera, safari, google chrome) on my computer). Perhaps you should update firefox to 3.5.6?

~G

Graphix 68 ---

-The program's extension has been from day 1 .c The filename is hangman.c . But perhaps it is my opensource editor/compiler Code::Blocks that only compiles to c++, I don't know.

-Although you now say I didn't correct bugs, I first adjusted your corrections in the program, then I removed the ones that resulted in an error.

The bugs I fixed:

~ char getWord(int wordN) { into char* getWord(int wordN){
~ char *words[200] into char* words200] = {0};
~ main() into int main(void)
~ char guessWord[] = getWord(wordNumber); into various lines

The rest returned error with the invalid conversion from *void to *char

-157 I don't understand what you mean, I allocated the memory of c at line 142 (c[50000]), and I don't quite understand why I should declare another pointer and then return that at line 157?

~G

Graphix 68 ---

Google first before you start posting. The number one result at Google is a geometric library named CGAL.

~G

Graphix 68 ---

Due to the fact it about a half day before you replied, i checked the code again and again (I guess this is called "learning" :)) and found the faults before your post. Anyway, the code is now working perfect, but if you have still have comments(s) on how the code below should be improved, please post them :).

Also, when I went your approach, it resulted an error:

invalid conversion from *void to *char

at the following part:

arofstr[f] = malloc(strlen(token)+1); // allocate memory for the string
strcpy(arofstr[f],token);

so I didn't add that part into the code.

Also the following code resulted in a windows error (it got through compiler, but resulted in an error when executed):

int i;
// free all the memory allocated for the strings
// It is ok to pass a NULL pointer to free(), so you
// don't have to test for that.
for(i  = 0; i < 200; i++)
{
    if( i != wordN)
         free(arofstr[i]);
}
// now you can return the string
return arofstr[wordN];

The full encoding that works:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <ctype.h>
#include <conio.h>
#include <time.h>
#include <string.h>

void prn_galg(int i) {
 switch (i) {
     case 0 :
      printf("Amount of wrong letters: %d\n\n", i);
      printf("\n");
      printf("\n");
      printf("\n");
      printf("\n");
      printf("\n");
      printf("\n");
      printf("____________\n\n");
     break;

     case 1 :
      printf("Amount of wrong letters: %d\n\n", i);
      printf("\n");
      printf("  |\n");
      printf("  |\n");
      printf("  |\n");
      printf("  |\n");
      printf("  |\n");
      printf("__|_________\n\n");
     break;

     case 2 :
      printf("Amount of wrong …
Graphix 68 ---

Well, I tried different things the past 2 hours, and at the end got it to work, but I still am not able to retrieve the word. I can open the file, read it, separate it, but I am not able to put the values in an array and then return the one with the random number identifier.

Please note the comments in the code, they explain the erros caused:

char randomNumber() {
srand(time(NULL));
int g = (rand() % 9);
return g;
}

char getWord(int wordN) {
  char c[50000];  /* declare a char array */
  int n;
  FILE *file;  /* declare a FILE pointer  */

  /* Opening words file */

  printf("Opening words.txt ....\n");
  file = fopen("words.txt", "r");
  printf("File opened successfully.\n");

  /* Incase the file can tbe openend */
  if(file==NULL) {
    printf("Error: can't open file.\n");
    return 1;
  }  else {

    /* Reading the contents of the file */

    n = fread(c, 1, 50000, file);
    c[n] = '\0';

    /* Separating the contents, divided by | */

    char arofstr[200];
    char *token = strtok(c, "|");
    int f = 0, j;
    while(token != NULL)
    {
      printf("[%s]\n", token); // This prints out [dude][monkey][guy]
      /* This is the problem of it: I cant use arofstr[f] = token
      If i used *token, it only returns the first letter (the pointer)
      */
      arofstr[f] = *token;
      token = strtok(NULL, "|");
      f++;
    }
    printf(arofstr);
    /* Closing the file */
    printf("Closing file...\n");
    fclose(file);
    printf("File closed succesfully.\n\n");
    /* This also returns an error, due to the fact that it isn't the …
Graphix 68 ---

Thanks for the help, i added them into my code and that part is now working fine.

Although it wasen't the solution to the while() problem. It turns out when the user entered for example an "a" and pressed enter, there were 2 characters: a and \n, so the while was executed twice. I corrected it by adding an if ( c != '\n' ) {} right after the scanf(). I hope other people will read this when they are having trouble with while(). The full code will be posted as soon as all problems are solved.

There is one last issue: retrieving words from a text file and then select the one with a random number. The following code is what I have so far, but when i execute it, a popup comes saying an error occured in the process (it does go through the compiler).

// This part works fine, and returns a number from 0-2
char randomNumber() {
srand(time(NULL));
int g = (rand() % 2);
return g;
}

// This part is the error-cause
char getWord(int wordN) {
  FILE *file;
  char c[50001];
  int r;
  // Opening the words file
  file = fopen("words.txt", "r");

  // Checking wether it is possible to open the file
  if(file==NULL) {
   printf("Error: can't open file.\n");
  } else {
    r = fread(c, 1, 50000, file);
   c[r] = '\0';
   pch = strtok (c," ,.-");
  return pch[wordN];
  }
  fclose(file);
}

Also, this is the part in main() in which I call the functions:

Graphix 68 ---

Hi,

I am currently learning C#, but when I made a program that allows the user to guess a word (in Dutch that's called "Galgje") it repeats the while-statement twice, ignoring the scanf(). I searched with Google and found out that the program is too fast for the user input. I tried different functions for user input (gets() and getline()) with no luck.

Does anyone have a suggestion on how to fix this?

Thanks in advance,
~G

The code:

#include <stdio.h>

#define MAX_WORD_LENGTH 30

void prn_galg(int i) {
 switch (i) {
     case 0 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 1 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 2 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 3 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 4 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 5 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 6 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 7 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 8 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 9 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

     case 10 :
      printf("Amount of wrong letters: %d\n\n", i);
     break;

 }
}


main() {
 /* Declaring variables */
 char currentWord[] = {'.', '.', '.', '.', '.', '.', '\0'}; /* The dot word */
 char guessWord[] = {'m', 'o', 'n', 'k', 'e', 'y', '\0'}; /* The word that needs to be guessed */
 int …
Graphix 68 ---

This should do the trick:

<script type="text/javascript">
var time = 10; //How long (in seconds) to countdown
var page = 'ddd.html'; //The destination.
var myInterval;
function countDown(){
time --;
get("message").innerHTML = time;
if(time == 0){
window.location = page;
clearInterval(myInterval);
time = 10;
}
}
function get(id){
if(document.getElementById) return document.getElementById(id);
if(document.all) return document.all.id;
if(document.layers) return document.layers.id;
if(window.opera) return window.opera.id;
}
function init(){
if(get('message')){
myInterval = setInterval(countDown, 1000);
get("message").innerHTML = time;
}
else{
setTimeout(init, 50);
}
}
document.onload = init();
</script>

~G

Graphix 68 ---

JQuery is one way to go,
You should take a look here:

http://www.learningjquery.com/2006/09/slicker-show-and-hide

First google before you post, there are alot of tutorials and explainations on the internet.

~G

Graphix 68 ---

You can place the game "Blackjack" by adding the following script to your website. All the information is included within the script, please do not remove the warranty or information. If you don't want such a big lap of code on your website, you can also place the following, as this is a link to exactly the same script:

<script src="http://www.symbolwebdesign.nl/webapps/blackjack.js" type="text/javascript"></script>

Have fun and good luck at playing Blackjack!

~G

Graphix 68 ---

This should do the trick:

<script type="text/javascript">
function toggleVis(id) {
var vis1 = document.getElementById(id).style.display;
if (vis1 == "inline") {
document.getElementById(id).style.display = "none";
} else {
document.getElementById(id).style.display = "inline";
}
}
</script>

<input type="checkbox" id="div1chk" onclick="toggleVis('div1');" />
<input type="checkbox" id="div2chk" onclick="toggleVis('div2');" />
<input type="checkbox" id="div3chk" onclick="toggleVis('div3');" />

<div id="div1" style="display:none;">
div1 showed
</div>
<div id="div2" style="display:none;">
 div2  showed
</div>
<div id="div3" style="display:none;">
div3  showed
</div>

~G

Graphix 68 ---

Hi all,

I made a script that can be used as a captcha. It shows a random amount of (roman) letters sliding by every 2000 miliseconds (thats why its called MatrixCaptcha. But I am not sure wether it is able to stop bots from spamming. Does anyone have a suggestion for improvement?

I know it's a bit long but you should try it out and see what you think about it!

The code:

<script type="text/javascript">
/*
=============================================================
=----------------===========================----------------=
=----------------==-----MatrixCaptcha-----==----------------=
=----------------===========================----------------=
=============================================================

###################---SCRIPT INFORMATION---###################
#                                                            #
# Script: MatrixCaptcha.js                                   #
#                                                            #
# Description: a script written in javascript. It is used    #
# to make sure that a human is filling in the form and not a #
# bot.                                                       #
#                                                            #
# Visit us at: www.symbolwebdesign.nl                        #
# Contact: info@symbolwebdesign.nl                           #
#                                                            #
##############################################################

########################---WARRANTY---########################
#                                                            #
#  This script is written and created by Symbol Webdesign.   #
# You are allowed to adjust this script to your own likings. #
#                                                            #
#    DO NOT REMOVE THIS WARRANTY OR THE SCRIPT INFORMATION   #
#                         AT ALL TIMES                       #
#                                                            #
#              Created by Symbol Webdesign ©2009             #
##############################################################

Further information:

The HTML of the script is compatible with (X)HTML transistional,
in order for this script to function properly, it is required to
put it in a form (as this is the entire purpose of the script)
You are able to retrieve the "TRUE" or "FALSE" values from it
by doing so (PHP) : …
Graphix 68 ---

Hi, try this:

var finalArray = new Array;
var testString = new Array;

testString[0] = "1,Jeremy,130,80;2,Ludwig,370,300;3,Jeancarlos,200,200;4,Luke,330,70;5,Someoneelse1,392,108";
testString[1] = "1,William,110,30;2,Lauren,370,300;3,Sophie,200,200;4,Charlotte,330,70;5,Someoneelse2,392,108";
// You can go on forever with adding strings here....

for (x = 0; x < testString.length; x++) {

var testArray = testString[x].split(";");

for(i = 0; i < testArray.length; i++)
{
var splitArray = testArray[i].split(","); // This return for example 1,Jeremy,130,80 of which splitArray[0] = 1
// splitArray.length) is 4 in the above example
finalArray[i] = new Array;
for (d = 0; d < splitArray.length; d++) {
finalArray[i][d] = splitArray[d];
// Use this to test the things that are returned:
// alert(finalArray[i][d]);
}
}
}

~G

Graphix 68 ---

This script can be used for star ratings on for example forum or music sites. The scriptinformation is included within the script.

~G

Graphix 68 ---

Well, I don't quite know what you don't understand, neither do I know why you should use innerHTML when creating a input in which you can enter your phonenumber.

Try the following?

<script type="text/javascript">
  function is_numeric(mixed_var){
   return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
  }

function checkPhoneNumber(phoneNo) {  
 var phoneRE = /^\d\d-\d\d\d\d\d\d\d\d$/;  // This matches XX-XXXXXXXX (e.g. 06-12345678)
 if (phoneNo.match(phoneRE)) {  
   alert("The phone number is valid!");
   return true;  
 } else {  
   alert("The phone number entered is invalid!");  
   return false;  
 }  
}
</script>
Enter your phonenumber below:<br />
<input type="text" id="phonenumber" name="phonenumber" maxlength="50" onchange="checkPhoneNumber(this.value)" />

~G

Graphix 68 ---

I checked my logbooks, but nothing appears at the date and time (in my example 23 november 16:40) of when it minimalized itself. Do you have any other suggestion?

~G

Graphix 68 ---

My suggestion:

<?php
function encode_num($number) {
switch($number) {

case 1 :
return "a";
break;

case 2 :
return "b";
break;

case 3 :
return "c";
break;

// ... Alot of code...
// ...Here comes all the other options...
// ...Alot of code...

default:
return "Invalid number";
break;
}
}

function decode_num($string) {
switch($string) {

case "a" :
return 1;
break;

case "b" :
return 2;
break;

case "c" :
return 3;
break;

// ... Alot of code...
// ...Here comes all the other options...
// ...Alot of code...

default:
return "Invalid string";
break;
}
}
echo "The letter 'c' decoded: ".decode_num('c')."<br />";
echo "The number '3' encoded: ".encode_num('3')."<br />";
?>

~G

Graphix 68 ---

Hi all,

I am currently having a small problem with my Windows XP computer: when I am for example playing Call of Duty 4 or Age of Mythology, the computer minimalizes the window by itself every half hour (or something like that). It doesn't happen with browsers or other applications.

I searched the problem up with Google, and found that a possible cause could be that another process requires attention and minimalizes all other windows. But I couldn't find the process responsible for that. I looked all the processes up at www.processlibrary.com but couldn't find out which one was responsible.

Strangly, when i looked up "smss.exe", processlibrary returned 7 different results: one that it is from Microsof Windows Operating System and the other 6 that it is a trojan (see the results here). The same thing with ctfmon.exe (see the results here).

Does anyone know how to solve this problem?

~G

Graphix 68 ---

Then the search-query would become:

SELECT * FROM simple_search WHERE $searchField LIKE '%$searchTerms%' OR $searchField2 LIKE '%$searchTerms2%'

You can add unlimited OR's and AND's

I hope this solves your problem :)

~G

Graphix 68 ---

Hi, there are a few things wrong with your code, it seems like you dont understand the difference between a name and an id. An id is unique, a name is not. You can not retrieve a name with getElementById(). The following code will work in all browsers:

<?php
mysql_connect("localhost", "crispwer_vishal", "vishal@123") or die(mysql_error());
mysql_select_db("crispwer_navy") or die(mysql_error()); 

$query = "SELECT * FROM depatment"; 
$result = mysql_query($query); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
// This function sets the usertype at disabled
function sle()
{
document.getElementById("userDept").disabled=true;
}
// This function decides whether the usertype should be enabled
function ss(niit)
{
var s = niit;
switch(s)
{
case '1':
	document.getElementById("userDept").disabled=true;
	break
case '2':
	document.getElementById("userDept").disabled=true;
	break
case '3':
	document.getElementById("userDept").disabled=false;
	break
default:
   document.write("ERROR") 
}
}
</script>
</head>
<body onLoad="sle()">
<p>&nbsp;</p>
<form id="loginForm" name="loginForm" method="post" action="userchek.php">
<hr />
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr>
  <td colspan="3">
    <input name="loginType" type="radio" id="1" onclick="ss(this.id); return true;';" value="administrator" />
    Administrator| 
    <input name="loginType" type="radio" id="2" onclick="ss(this.id); return true;" value="storekeeper" />
    Store Keeper |
    <input name="loginType" type="radio" id="3" onclick="ss(this.id); return true;" value="user" />
    User</td>
  </tr>
  </tr>
  <tr>
    <td colspan="3">User Department
        <select id="userDept" name="userDept">
		<option>Select</option>
		<?php while($row = mysql_fetch_array($result))
		{ 
		echo "<option>$row[Dept_Name]</option>";
		}?>
		</select>
    </td>
  </tr>
    <tr>
      <td width="111"><b>Login</b><td colspan="2"><input name="login" type="text" class="textfield" id="login" /></td>
    </tr>
    <tr>
      <td><b>Password</b></td>
      <td colspan="2"><br />
        <input name="password" type="password" class="textfield" id="password" />
      <br /></td>
    </tr>
    <tr>
      <td><input type="submit" name="Submit" onclick="newwindow();" value="     LOGIN …
Graphix 68 ---

Ok, first of all: i thought you had made correct html, with the appropiate values in the options/select. But no. You had no "s" infront of the values. I made a new table that corresponded to yours. And checked the entire code. The following code works fine, if it still doesnt work: update your PHP version.

<?php
$dbHost = 'localhost'; // localhost will be used in most cases
// set these to your mysql database username and password.
$dbUser = 'root'; 
$dbPass = '';
$dbDatabase = 'test'; // the database you put the table into.
$con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error());

mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());

// Set up our error check and result check array
$error = array();
$results = array();
 
if (isset($_GET['search']) && isset($_GET['field'])) {
   $searchTerms = trim($_GET['search']);
   $searchTerms = strip_tags($searchTerms); // remove any html/javascript.
  $searchField = trim($_GET['field']);
  $searchField = strip_tags($searchField);
  $searchField = addslashes($searchField);
 
   if (strlen($searchTerms) < 3) {
      $error[] = "Search terms must be longer than 3 characters.";
   }else {
      $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
   }
 
 
   if (count($error) < 1) {
      $searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE $searchField LIKE '%$searchTerms%' ";         
 echo $searchSQL;
      @$searchResult = mysql_query($searchSQL);
 
      if (mysql_num_rows($searchResult) < 1 || !$searchResult) {
         $error[] = "The search term provided {$searchTerms} yielded no results.";
      }else {
         $results = array(); 
         $i = 1;
         while ($row = mysql_fetch_assoc($searchResult)) {
            $results[] = "{$i}: {$row['stitle']}<br />{$row['sdescription']}<br />{$row['sbody']}<br /><br />"; …
Graphix 68 ---
$error = array();
$results = array();

if (isset($_GET['search']) && isset($_GET['field'])) {
   $searchTerms = trim($_GET['search']);
   $searchTerms = strip_tags($searchTerms); // remove any html/javascript.
  $searchField = trim($_GET['field']);
  $searchField = strip_tags($searchField);
  $searchField = addslashes($searchField);
   
   if (strlen($searchTerms) < 3) {
      $error[] = "Search terms must be longer than 3 characters.";
   }else {
      $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
   }
   
 
   if (count($error) < 1) {
      $searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE $searchField LIKE '%$searchTerms%' ";         
         
      @$searchResult = mysql_query($searchSQL);
     
      if (mysql_num_rows($searchResult) < 1 || !$searchResult) {
         $error[] = "The search term provided {$searchTerms} yielded no results.";
      }else {
         $results = array(); 
         $i = 1;
         while ($row = mysql_fetch_assoc($searchResult)) {
            $results[] = "{$i}: {$row['stitle']}<br />{$row['sdescription']}<br />{$row['sbody']}<br /><br />";
            $i++;
          } // End of while
       } // End of else
    } // End of error check
} // End of isset()
Graphix 68 ---

I don't know whether this is the best solution, but here it is:

<?php
// Note: this MUST be on the top of the page, without any whitespace whatsoever infront of it
session_start();
?>
<?php
$theimagename = "05-5098-40293050.jpg"; // You have retrieved this from your upload script
$_SESSION['imagename'] = $theimagename;
?>

Then you can retrieve that session variable on the next page:

<?php
// Note: this MUST be on the top of the page, without any whitespace whatsoever infront of it
session_start();
?>
<?php
$theimagename = $_SESSION['imagename'];
echo $theimagename;
?>
Graphix 68 ---

First of all: it doesn't seem like you have had alot of experience with regular XHTML and as so don't know how a form works.

If you would like to have a form that is submitted to another page and has a reset button, use something like this:

<form action="formhandler.php" method="post">
Enter something here!<br />
<input type="text" maxlength="255" name="someText" /><br />
<br />
<input type="submit" name="submitbutton" value="Submit this form!" /><input type="reset" name="resetbutton" value="Delete all the values of the form!" />
</form>

For more information about forms and such, please see some of the following links:

http://www.w3schools.com/html/html_forms.asp

~G

Graphix 68 ---

i have no idea what you table/database structure is, neither do i know what columns. So the query:

$searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE [B]field[/B]='$searchField' ";

is just an example. You will need to replace the field with the corresponding column.

~G

Graphix 68 ---

Ok, i have been thinking, and this is the script I came up with. Please not: this takes a gigantic amount of memory and your browser can stop if you make the onclick in to onmouseover or if you spamclick on the image.

Anyway here it is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Hiding an image</title>
<style type="text/css">

</style>
</head>
<body>
<script type="text/javascript">
//
// This script only works in Firefox, i recommend you make a img
// with the name sun.bmp and 84x84 size
//
var height = 84;
var width = 84;
function lightImg(event) {
// Retrieving the posx and posy of the mouse
pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("container").offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("container").offsetTop;
// Making all the pixels black
for (var a = 0; a < height; a++) {
for (var s = 0; s < width; s++) {
document.getElementById(a + '-' + s).style.display = "inline";
}
}
// Making a square of 40 by 40 not displayed
var leftside = pos_x - 20;
var rightside = pos_x + 20;
var topside = pos_y - 20;
var underside = pos_y + 20;
for (var d = leftside; d < rightside; d++) {
for (var z = topside; z < underside; z++) {
document.getElementById(z + '-' + d).style.display = "none"; // Dont ask me why it is z d and not d z, it doesnt work with d z???
}
}
}

// Making …
Graphix 68 ---

Hi, you can try this:

1. Make 2 images using a image editor (PhotoShop or something like that), one is a bit darker as the other (for example: darkImg.jpg and lightImg.jpg)
2. Use the onmouseover and onmouseout events to show the lighter version when someone scrolls over and the darker version when not (and by default the dark image) (see code below)

<img src="darkImg.jpg" onmouseout="this.src='darkImg.jpg'" onmouseover="this.src='lightImg.jpg'" alt="An Image" title="Scroll over to illuminate" />

~G

Graphix 68 ---

Try this:

$error = array();
$results = array();

if (isset($_GET['search']) && isset($_GET['field'])) {
   $searchTerms = trim($_GET['search']);
   $searchTerms = strip_tags($searchTerms); // remove any html/javascript.
  $searchField = trim($_GET['field']);
  $searchField = strip_tags($searchField);
  $searchField = addslashes($searchField);
   
   if (strlen($searchTerms) < 3) {
      $error[] = "Search terms must be longer than 3 characters.";
   }else {
      $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
   }
   
 
   if (count($error) < 1) {
      $searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE field='$searchField' ";         
         
      $searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");
      
      if (mysql_num_rows($searchResult) < 1) {
         $error[] = "The search term provided {$searchTerms} yielded no results.";
      }else {
         $results = array(); 
         $i = 1;
         while ($row = mysql_fetch_assoc($searchResult)) {
            $results[] = "{$i}: {$row['stitle']}<br />{$row['sdescription']}<br />{$row['sbody']}<br /><br />";
            $i++;
          } // End of while
       } // End of else
    } // End of error check
} // End of isset()
Graphix 68 ---

It doesn't work in IE because you have neglected to add doctype and such. I also think the script is not very well written.... Here is a better one:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Formtest</title>
		<script type="text/javascript">
		function clearElement(id)
		{
   			document.getElementById(id).innerHTML = "";
   		}
			  
		function clearFormElement(id)
		{
   			document.getElementById(id).value = "";
   		}
			  
		function hideElement(id)
		{
			var hideElement = document.getElementById(id);
			hideElement.style.visibility = "hidden";
		}
		
		function unhideElement(id)
		{
			var hideElement = document.getElementById(id);
			hideElement.style.visibility = "visible";
		}
		
		</script>
</head>
<body>

	<a href="#" onclick="clearElement('myForm')">Delete the form (it can not be undeleted: gone=gone)</a><br />
	<a href="#" onclick="hideElement('myForm')">Hide the form</a><br />
	<a href="#" onclick="unhideElement('myForm')">Unhide the form</a><br />
	<a href="#" onclick="clearFormElement('myInput')">Clear the input box value</a><br />
		
	<!-- The form -->
		
	<form action="" id="myForm" name="myForm">
			
		<input size="30" type="text" name="myInput" id="myInput" value="This is a value of my input" />
			
	</form>
</body>
</html>

~G

Graphix 68 ---

Try this:

<script language="JavaScript" type="text/JavaScript">
<!--
menu_status = new Array();

function showHide(theid){
    if (document.getElementById) {
          var switch_id = document.getElementById(theid);
        if(menu_status[theid] != 'show') {
           switch_id.className = 'show';
           menu_status[theid] = 'show';
           set_cookie(theid,'hide');
        }else{
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
           set_cookie(theid,'show');
        }
    }
}

function showHideAll()
{
      var menuState = get_cookie ('mymenu1');
      menu_status['mymenu1']=menuState;
      showHide('mymenu1');

      menuState = get_cookie ('mymenu2');
      menu_status['mymenu2']=menuState;
      showHide('mymenu2');
	  
	  menuState = get_cookie ('mymenu3');
      menu_status['mymenu3']=menuState;
      showHide('mymenu3');
	  
	  menuState = get_cookie ('mymenu4');
      menu_status['mymenu4']=menuState;
      showHide('mymenu4');
	  
}



function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );


  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );

  if ( secure )
        cookie_string += "; secure";

  document.cookie = cookie_string;
}

//-->
</script>

<style type="text/css">
.menu1{
	background-color:#2a4c79;
	padding-left:5px;
	padding-top:2px;
	padding-bottom: 2px;
	display:block;
	text-decoration: none;
	color: #ffffff;
	height: 20px;
	font-family:Tahoma;
	font-size:12px;
	border-top:solid 1px #000000;
}

.menu2{
	background-color:#2a4c79;
	padding-left:5px;
	padding-top:2px;
	padding-bottom: 2px;
	display:block;
	text-decoration: none;
	color: #ffffff;
	height: 20px;
	font-family:Tahoma;
	font-size:12px;
	border-top:solid 1px #000000;
}

.menu3{
	background-color:#2a4c79;
	padding-left:5px;
	padding-top:2px;
	padding-bottom: 2px;
	display:block;
	text-decoration: none;
	color: #ffffff;
	height: 20px;
	font-family:Tahoma;
	font-size:12px;
	border-top:solid 1px #000000;
}
.menu4{
	background-color:#2a4c79;
	padding-left:5px;
	padding-top:2px; …
Graphix 68 ---

Why would you use 2 tables for the exactly same purpose? Why don't you just make the following two table:

table "surveyresults":
qa_id INT(9) AUTO_INCREMENT NOT NULL,
question CHAR(255),
answer LONGTEXT,
sid INT(9) NOT NULL,

And use the following code:

<?php
	require_once('auth.php');
	require_once('config.php');
	//
        // Retrieving which survey it is and who filled it in
        //
	$date=date("F j, Y, g:i a");
	$stitle = $_POST['stitle'];
	$stitle = ucwords($stitle);
	$name = $_SESSION['SESS_NAME'];
	$member_id = $_SESSION['SESS_MEMBER_ID'];

//
// Saving in the database who filled in the survey, what survey and when
//

$query = "INSERT INTO survey (stitle, sdate, name, member_id) VALUES ('$stitle', '$date', '$name', '$member_id')";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());

    $sid = mysql_insert_id();

    // reset variables
    unset($query);
    unset ($result);
	
// 
// Retrieving the answers
//
foreach ($_POST['options'] as $o) {
        if (trim($o) != '') {
            $answers[] = $o;
        }
}
//
// Retrieving the questions
//
    foreach ($_POST['questions'] as $q) {
        if (trim($q) != '') {
            $questions[] = $q;
        }
}

//
// Counting the amount of questions and answers
//
$question_amount = count($questions);
$answer_amount = count($answers);

//
// Inserting the answers and questions
//

for ($i=0; $i < $question_amount; $i++) {
 $answer = $answers[$i];
 $question = $questions[$i];
 $query = "INSERT INTO surveyresults (sid, question, answer) VALUES ('$sid', '$question','$answer')";
   $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
    }

    //Check whether the query was successful or not
	if($result) {
		header("location: surveypreview.php");
		exit();
	}else {
		echo '<script>alert("Query Failed. Please try again !!!");</script>';
		echo '<script>history.back(1);</script>';
	}

    mysql_close();
?>
Graphix 68 ---

The below code will show the results just like you wanted:

<?php
$query1 = "SELECT * FROM table1";
$result1 = mysql_query($query1);
while ($row1 = mysql_fetch_array($result1)) {
$qid = $row1['qid'];
$qtitle = $row1['qtitle'];
$query2 = "SELECT * FROM table2 WHERE qid='$qid'";
$result2 = mysql_query($query2);
echo "<span style=\"text-decoration:underline; font-weight:bold;\">".$qtitle."</span><br />";
while ($row2 = mysql_fetch_array($result2)) {
echo "".$atitle."<br />";
}
echo "<br />";
}
?>

~G

Graphix 68 ---

It depends on what and howmuch columns you have in your table. For example, ExampleTable exists out of 5 columns:

user CHAR(255), <- PRIMARY KEY
firstname CHAR(255),
lastname CHAR(255),
telephone INT(20) and
zip INT(7)

Then if you execute the following query:

<?php
//
// Creating query and executing it
//
$query = "SELECT * FROM ExampleTable";
$result = mysql_fetch_array($query);
//
// As long as $row has a result, it executes what is inside the {}
//
while ($row = mysql_fetch_array($result)) {
//
// Putting $row[''] variables in separate variables
//
$user = $row['user'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$telephone = $row['telephone'];
$zip = $row['zip'];
//
// Showing the result
//
echo "
User: ".$user."<br />
Firstname: ".$firstname."<br />
Lastname: ".$lastname."<br />
Telephone: ".$telephone."<br />
Zip: ".$zip."<br /><br />";
}
?>

Sorry saw horrible mistake in my post:

$result = mysql_fetch_array($query);

needs to be

$result = mysql_query($query);

~G

Graphix 68 ---

It depends on what and howmuch columns you have in your table. For example, ExampleTable exists out of 5 columns:

user CHAR(255), <- PRIMARY KEY
firstname CHAR(255),
lastname CHAR(255),
telephone INT(20) and
zip INT(7)

Then if you execute the following query:

<?php
//
// Creating query and executing it
//
$query = "SELECT * FROM ExampleTable";
$result = mysql_fetch_array($query);
//
// As long as $row has a result, it executes what is inside the {}
//
while ($row = mysql_fetch_array($result)) {
//
// Putting $row[''] variables in separate variables
//
$user = $row['user'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$telephone = $row['telephone'];
$zip = $row['zip'];
//
// Showing the result
//
echo "
User: ".$user."<br />
Firstname: ".$firstname."<br />
Lastname: ".$lastname."<br />
Telephone: ".$telephone."<br />
Zip: ".$zip."<br /><br />";
}
?>
Graphix 68 ---

The if(selectionStart)-statement didn't work as there was no text selected. I extended the sniffer and came up with this easy solution. As i made a separate method of placing the bb-code with getSelection(), I just made sure that the browser wasn't IE (as only IE doesn't support selectionStart and all other browsers are an extension of Netscape Navigator)

if(navigator.appName != "Microsoft Internet Explorer"){ 
isFF = true; 
}

~G

Graphix 68 ---

Thank you, that solved the problem :). I also tryed with Google Chrome and Safari, but both can't retrieve the selected text. I guess iil have to live with it that there are only 2 that support BB-code: IE and FF (luckily the 2 most used browsers on the world). Thread solved.

~G

Graphix 68 ---

Ok, i thought that part of the code was the only needed, but here is it all :) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head>
<body>
<script type="text/javascript"> 
function addBB(t){ 
//crappy browser sniffer 
var isFF = false; 
var textselected = false; 
if(navigator.userAgent.toLowerCase().indexOf("firefox") > 0){ 
isFF = true; 
} 
var myArea = document.getElementById("text"); 
var begin,selection,end; 
if (isFF == true){ 
if (myArea.selectionStart!= undefined) {  
begin = myArea.value.substr(0, myArea.selectionStart);  
selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);  
end = myArea.value.substr(myArea.selectionEnd); 
if (selection.length > 0){ 
textselected = true; 
} 
} 
}else{ 
if (window.getSelection){ 
selection = window.getSelection(); 
}else if (document.getSelection){ 
selection = document.getSelection(); 
}else if (document.selection){ 
selection = document.selection.createRange().text; 
} 
var startPos = myArea.value.indexOf(selection); 
if (startPos >= 0 && t != "image"){ 
var endPos = myArea.value.indexOf(selection) + selection.length; 
begin = myArea.value.substr(0,startPos); 
end = myArea.value.substr(endPos, myArea.value.length); 
textselected = true; 
} 
} 
if(textselected == true){ 
switch (t){ 
case "color": 
var color = window.prompt("Enter the color in english below:");
if (color != "" && color != "undefined" && color != "null" && color != 0 && color != null) {
startTag = "[color=" + color + " ]"; 
endTag = "[/color ]\n"; 
}
break; 

case "bold":
startTag = "[b ]";
endTag = "[/b ]";
break;

case "italics":
startTag = "[i ]";
endTag = "[/i ]";
break;

case "underline":
startTag = "[u ]";
endTag = "[/u ]";
break;

case "link":
var link = window.prompt("Enter the link below:");
if (link != "" && …
Graphix 68 ---

Oops, the code was incomplete, here is full encoding for IE:

if (window.getSelection){ 
selection = window.getSelection(); 
}else if (document.getSelection){ 
selection = document.getSelection(); 
}else if (document.selection){ 
selection = document.selection.createRange().text; 
} 
var startPos = myArea.value.indexOf(selection); 
if (startPos >= 0){ 
var endPos = myArea.value.indexOf(selection) + selection.length; 
begin = myArea.value.substr(0,startPos); 
end = myArea.value.substr(endPos, myArea.value.length); 
textselected = true; 
}
Graphix 68 ---

I believe you don't understand what DaniWeb Community is about; we are here to support people with IT problems. We are not your little slaves you can command and expect us to write an entire script for you. Atleast have the decency to try to make the script yourself. When you stumble on a problem you can not solve yourself and haven't found a solution using Google, then you can post it here on Daniweb and we will be happy to help you then.

~G

Graphix 68 ---

I am currently having a problem with my BB-code editor, like most things it works great in FF, but i have an issue with IE: whenever i select a word that has already been previously typed, it selects that word instead of the one i selected.

Here is the selection part of my editor:

if (window.getSelection){ 
selection = window.getSelection(); 
}else if (document.getSelection){ 
selection = document.getSelection(); 
}else if (document.selection){ 
selection = document.selection.createRange().text; 
}

Example:

The text: the cats attack the other cats
I selected the second "cats", but the script keeps returning the first "cats"

Does anyone have a suggestion on how to fix this?