This topic is locked

onFocus='clearDefault(this)'

8/23/2008 10:38:53 PM
PHPRunner General questions
I
iripais author

How can I add this function on my forms?

onFocus="clearDefault(this)"

J
Jane 8/25/2008

Hi,
here is a sample:

<script>

document.forms.editform.value_FieldName.onfocus=function()

{

clearDefault(this);

}

</script>

I
iripais author 8/25/2008

Hi Jane
I know the script.
The 1st problem is: If I place it in the had of my "templates/contacts_add.php" it gives me an php error:

The second is: Where do I place the "onFocus="clearDefault(this)"? is it here?:{build_edit_control field="nome" mode="add" value="Nome *"}

Hi,

here is a sample:

J
Jane 8/25/2008

Hi,
add {literal} and {/literal} around your JavaScript code in the HTML.

To add your code to the element control directly edit generatedinclude/commonfunctions.php file.

I
iripais author 8/25/2008

Hi,

add {literal} and {/literal} around your JavaScript code in the HTML.

To add your code to the element control directly edit generatedinclude/commonfunctions.php file.


Ok, I've got the firdt one.
But I just don't know where to update the commonfunctions.php with the onFocus="clearDefault(this)":-(

J
Jane 8/25/2008

Check BuildEditControl function in the include/commonfunctions.php file.

I
iripais author 8/25/2008

ok, I have something like this:

function BuildEditControl($field , $value, $format, $edit, $secondfield=false, $id="")

{

global $rs,$data,$strTableName,$filenamelist,$keys;

$cfieldname=GoodFieldName($field);

$cfield="value".GoodFieldName($field);

$ctype="type
".GoodFieldName($field);

if($secondfield)

{

$cfield="value1".GoodFieldName($field);

$ctype="type1
".GoodFieldName($field);

}

$type=GetFieldType($field);

$arr="";
$iquery="field=".rawurlencode($field);

$keylink="";

if($strTableName=="emails")

{

$keylink.="&key1=".rawurlencode(@$keys["id"]);

$iquery.=$keylink;

}

if($strTableName=="contactos")

{

$keylink.="&key1=".rawurlencode(@$keys["id"]);

$iquery.=$keylink;

}

if($format==EDIT_FORMAT_FILE && $edit==MODE_SEARCH)

$format="";

if($format==EDIT_FORMAT_TEXT_FIELD)

{

if(IsDateFieldType($type))

echo '<input type="hidden" name="'.$ctype.'" value="date'.EDIT_DATE_SIMPLE.'">'.GetDateEdit($field,$value,0,$secondfield,$edit,$id);

else

{

if($edit==MODE_SEARCH)

echo '<input type="text" autocomplete="off" name="'.$cfield.'" '.GetEditParams($field).' value="'.htmlspecialchars($value).'">';

else

echo '<input type="text" name="'.$cfield.'" '.GetEditParams($field).' value="'.htmlspecialchars($value).'">';

}

}

else if($format==EDIT_FORMAT_TIME)

{

echo '<input type="hidden" name="'.$ctype.'" value="time">';

if(IsDateFieldType($type))

{

$dbtime=db2time($value);
if(count($dbtime))

$val=format_time($dbtime);

else

$val="";

}

else

{

$arr=parsenumbers($value);

if(count($arr))

{

$dbtime=array(0,0,0);

while(count($arr)<3)

$arr[]=0;

$dbtime[]=$arr[0];

$dbtime[]=$arr[1];

$dbtime[]=$arr[2];

$val=format_time($dbtime);

}

else

$val="";

}

echo '<input type="text" name="'.$cfield.'" '.GetEditParams($field).' value="'.htmlspecialchars($val).'">';

}

else if($format==EDIT_FORMAT_TEXT_AREA)

{
$nWidth = GetNCols($field);

$nHeight = GetNRows($field);

if(UseRTE($field))

{

$value = RTESafe($value);
if($edit==MODE_INLINE_EDIT || $edit==MODE_INLINEADD)

{

$cfield.="
".$id;

$cfieldname.="_".$id;

$browser="";

if(@$_REQUEST["browser"]=="ie")

$browser="&browser=ie";

echo "<iframe scrolling=no name=\"".$cfield."\" style='width: " . ($nWidth+1) . "px;height: " . ($nHeight+1) . "px;'";

echo " src=\"".GetTableURL($strTableName)."_rte.php?id=".$id."&".$iquery.$browser."\">";

echo "</iframe>";

}

else

{

echo "<script language=\"JavaScript\" type=\"text/javascript\">\r\n".

"writeRichText('".$cfield."', '".$value."', " . $nWidth . ", " . $nHeight . ", true, false);\r\n".

"</script>";

}
}

else

echo '<textarea name="'.$cfield.'" style="width: ' . $nWidth . 'px;height: ' . $nHeight . 'px;">'.htmlspecialchars($value).'</textarea>';

}

else if($format==EDIT_FORMAT_PASSWORD)

echo '<input type="Password" name="'.$cfield.'" '.GetEditParams($field).' value="'.htmlspecialchars($value).'">';

else if($format==EDIT_FORMAT_DATE)

echo '<input type="hidden" name="'.$ctype.'" value="date'.DateEditType($field).'">'.GetDateEdit($field,$value,DateEditType($field),$secondfield,$edit,$id);

else if($format==EDIT_FORMAT_RADIO)

BuildRadioControl($field,$value,$secondfield,$id);

else if($format==EDIT_FORMAT_CHECKBOX)

{

if($edit==MODE_ADD || $edit==MODE_INLINE_ADD || $edit==MODE_EDIT || $edit==MODE_INLINE_EDIT)

{

$checked="";

if($value && $value!=0)

$checked=" checked";

echo '<input type="hidden" name="'.$ctype.'" value="checkbox"><input type="Checkbox" name="'.$cfield.'" '.$checked.'>';

}

else

{

echo '<input type="hidden" name="'.$ctype.'" value="checkbox">';

echo '<select name="'.$cfield.'">';

$val=array("none","on","off");

$show=array("","True","False");

foreach($val as $i=>$v)

{

$sel="";

if($value===$v)

$sel=" selected";

echo '<option value="'.$v.'"'.$sel.'>'.$show[$i].'</option>';

}

echo "</select>";

}

}

else if($format==EDIT_FORMAT_DATABASE_IMAGE || $format==EDIT_FORMAT_DATABASE_FILE)

{

$disp="";

$strfilename="";

$onchangefile="";

if($edit==MODE_EDIT || $edit==MODE_INLINEEDIT)

{

if($id<>"")

$ctype.="
".$id;

$value=db_stripslashesbinary($value);

$itype=SupposeImageType($value);

$thumbnailed=false;

$thumbfield="";
if($itype)

{

if($thumbnailed)

{

$disp="<a target=_blank href=\"".GetTableURL($strTableName)."_imager.php?".$iquery."\">";

$disp.= "<img name=\"".$cfield."\" border=0";

$disp.=" src=\"".GetTableURL($strTableName)."_imager.php?field=".rawurlencode($thumbfield)."&alt=".rawurlencode($field).$keylink."\">";

$disp.= "</a>";

}

else

$disp='<img name="'.$cfield.'" border=0 src="'.GetTableURL($strTableName).'_imager.php?'.$iquery.'">';

}

else

{

if(strlen($value))

$disp='<img name="'.$cfield.'" border=0 src="images/file.gif">';

else

$disp='<img name="'.$cfield.'" border=0 src="images/no_image.gif">';

}

// filename

if($format==EDIT_FORMAT_DATABASE_FILE && !$itype && strlen($value))

{

if(!($filename=@$data[GetFilenameField($field)]))

$filename="file.bin";

$disp='<a href="'.GetTableURL($strTableName).'_getfile.php?filename='.htmlspecialchars($filename).'&'.$iquery.'".>'.$disp.'</a>';

}

// filename edit

if($format==EDIT_FORMAT_DATABASE_FILE && GetFilenameField($field))

{

if(!($filename=@$data[GetFilenameField($field)]))

$filename="";

if($edit==MODE_INLINEEDIT)

{

$strfilename='
'."Nome de Arquivo".'&nbsp;&nbsp;<input id="filename
'.$cfieldname.''.$id.'" name="filename'.$cfieldname.'" size="20" maxlength="50" value="'.htmlspecialchars($filename).'">';

$onchangefile.="var path=$('#".$cfield."".$id."').val(); var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; $('#filename".$cfieldname."".$id."').val(path.substr(pos+1));";

}

else

{

$strfilename='
'."Nome de Arquivo".'&nbsp;&nbsp;<input name="filename
'.$cfieldname.'" size="20" maxlength="50" value="'.htmlspecialchars($filename).'">';

$onchangefile.="var path=this.form.elements['".jsreplace($cfield)."'].value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; this.form.elements['filename_".jsreplace($cfieldname)."'].value=path.substr(pos+1);";

}

}

$strtype='
<input type="Radio" name="'.$ctype.'" value="file0" checked>'."Manter";

if(strlen($value) && !IsRequired($field))

{

$strtype.='<input type="Radio" name="'.$ctype.'" value="file1">'."Elimina Selecionados";

if ($edit==MODE_INLINE_EDIT ) {

$onchangefile.='$(\'input[@type=radio][@value=file2][@name='.$ctype.']\').get(0).checked=true;';

} else {

$onchangefile.='this.form.elements[\''.jsreplace($ctype).'\'][2].checked=true;';

}

}

else {

if ($edit==MODE_INLINE_EDIT) {

$onchangefile.='$(\'input[@type=radio][@value=file2][@name='.$ctype.']\').get(0).checked=true;';

} else {

$onchangefile.='this.form.elements[\''.jsreplace($ctype).'\'][1].checked=true;';

}

}
$strtype.='<input type="Radio" name="'.$ctype.'" value="file2">'."Atualizar";

}

else

{

// if Add mode

$strtype='<input type="hidden" name="'.$ctype.'" value="file2">';

if($format==EDIT_FORMAT_DATABASEFILE && GetFilenameField($field))

{

$strfilename='
'."Nome de Arquivo".'&nbsp;&nbsp;<input name="filename
'.$cfieldname.'" size="20" maxlength="50">';

if($edit==MODE_INLINEADD)

$onchangefile.="var path=$('#".$cfield."
".$id."').val(); var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; $('#filename".$cfieldname."".$id."').val(path.substr(pos+1));";

else

$onchangefile.="var path=this.form.elements['".jsreplace($cfield)."'].value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; this.form.elements['filename_".jsreplace($cfieldname)."'].value=path.substr(pos+1);";

}

}

if($onchangefile)

$onchangefile='onChange="'.$onchangefile.'"';

if($edit==MODE_INLINE_EDIT && $format==EDIT_FORMAT_DATABASEFILE)

$disp="";

echo $disp.$strtype.'
<input type="File" id="'.$cfield."
".$id.'" name="'.$cfield.'" '.$onchangefile.'>'.$strfilename;

}

else if($format==EDIT_FORMAT_LOOKUP_WIZARD)

BuildSelectControl($field, $value, $arr, $secondfield, $edit,$id);

else if($format==EDIT_FORMAT_HIDDEN)

echo '<input type="Hidden" name="'.$cfield.'" value="'.htmlspecialchars($value).'">';

else if($format==EDIT_FORMAT_READONLY)

echo '<input type="Hidden" name="'.$cfield.'" value="'.htmlspecialchars($value).'">';

else if($format==EDIT_FORMAT_FILE)

{

$disp="";

$strfilename="";

$onchangefile="";

$function="";

if($edit==MODE_EDIT || $edit==MODE_INLINEEDIT)

{

// show current file

if($id<>"")

$ctype.="
".$id;

if(Format($field)==FORMAT_FILE || Format($field)==FORMAT_FILE_IMAGE)

{

$disp=GetData($data,$field,Format($field))."
";

}

$filename=$value;

if ( $edit==MODE_INLINE_EDIT ) {

$function="";

} else {

$function='<script language="Javascript">

function controlfilename'.$cfieldname.'(enable)

{

if(enable)

{

document.forms.editform.'.$cfield.'.style.backgroundColor="white";

document.forms.editform.'.$cfield.'.disabled=false;

}

else

{

document.forms.editform.'.$cfield.'.style.backgroundColor="gainsboro";

document.forms.editform.'.$cfield.'.disabled=true;

}

}

</script>';

}

// filename edit

$filename_size=30;

if(UseTimestamp($field))

$filenamesize=50;

$strfilename='<input type=hidden name="filename
'.$cfieldname.'" value="'.htmlspecialchars($filename).'">
'."Nome de Arquivo".'&nbsp;&nbsp;<input style="background-color:gainsboro" disabled id="'.$cfield.'_'.$id.'" name="'.$cfield.'" size="'.$filename_size.'" maxlength="100" value="'.htmlspecialchars($filename).'">';

if ( $edit==MODE_INLINEEDIT ) {

$onchangefile.="var path=$('[@id=file
".$cfieldname."".$id."]').val(); var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; $('#".$cfield."".$id."').css('backgroundColor','white');$('#".$cfield."".$id."')[0].disabled=false;";

if(UseTimestamp($field))

$onchangefile.="$('[@id=".$cfield."
".$id."]').val(addTimestamp(path.substr(pos+1))); ";

else

$onchangefile.="$('[@id=".$cfield."".$id."]').val(path.substr(pos+1)); ";

$strtype='
<input type="Radio" name="'.$ctype.'" value="upload0" checked onclick="$(\'[@id='.$cfield.'
'.$id.']\').css(\'backgroundColor\',\'gainsboro\');$(\'[@id='.$cfield.''.$id.']\')[0].disabled=true;">'."Manter";

} else {

$onchangefile.="var path=this.form.file
".$cfieldname.".value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos; controlfilename".$cfieldname."(true);";

if(UseTimestamp($field))

$onchangefile.="this.form.".$cfield.".value=addTimestamp(path.substr(pos+1)); ";

else

$onchangefile.="this.form.".$cfield.".value=path.substr(pos+1); ";

$strtype='
<input type="Radio" name="'.$ctype.'" value="upload0" checked onclick="controlfilename'.$cfieldname.'(false)">'."Manter";

}
if(strlen($value) && !IsRequired($field))

{

if ($edit==MODE_INLINEEDIT) {

$strtype.='<input type="Radio" name="'.$ctype.'" value="upload1" onclick="$(\'[@id='.$cfield.'
'.$id.']\').css(\'backgroundColor\',\'gainsboro\');$(\'[@id='.$cfield.'_'.$id.']\')[0].disabled=true;">'."Elimina Selecionados";

$onchangefile.='$(\'input[@type=radio][@value=upload2][@name='.$ctype.']\').get(0).checked=true;';

} else {

$strtype.='<input type="Radio" name="'.$ctype.'" value="upload1" onclick="controlfilename'.$cfieldname.'(false)">'."Elimina Selecionados";

$onchangefile.='this.form.'.$ctype.'[2].checked=true;';

}

}

else {

if ($edit==MODE_INLINE_EDIT) {

$onchangefile.='$(\'input[@type=radio][@value=upload2][@name='.$ctype.']\').get(0).checked=true;';

} else {

$onchangefile.='this.form.'.$ctype.'[1].checked=true;';

}

}

if ($edit==MODE_INLINEEDIT) {

$strtype.='<input type="Radio" name="'.$ctype.'" value="upload2" onclick="$(\'[@id='.$cfield.'
'.$id.']\').css(\'backgroundColor\',\'white\');$(\'[@id='.$cfield.'_'.$id.']\')[0].disabled=false;">'."Atualizar";

} else {

$strtype.='<input type="Radio" name="'.$ctype.'" value="upload2" onclick="controlfilename'.$cfieldname.'(true)">'."Atualizar";

}

}

else

{

// if Adding record

$filename_size=30;

if(UseTimestamp($field))

$filename_size=50;

$strtype='<input type="hidden" name="'.$ctype.'" value="upload2">';

$strfilename='
'."Nome de Arquivo".'&nbsp;&nbsp;<input name="'.$cfield.'" size="'.$filename_size.'" maxlength="100">';

if($edit==MODE_INLINEADD)

{

$onchangefile.="var path=$('[@id=file
".$cfieldname."".$id."]').val(); var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos;";

if(UseTimestamp($field))

$onchangefile.=" $('[@id=".$cfield."
".$id."]').val(addTimestamp(path.substr(pos+1)));";

else

$onchangefile.=" $('[@id=".$cfield."".$id."]').val(path.substr(pos+1));";

}

else

{

$onchangefile.="var path=this.form.file
".$cfieldname.".value; var wpos=path.lastIndexOf('\\\\'); var upos=path.lastIndexOf('/'); var pos=wpos; if(upos>wpos) pos=upos;";

if(UseTimestamp($field))

$onchangefile.=" this.form.".$cfield.".value=addTimestamp(path.substr(pos+1));";

else

$onchangefile.=" this.form.".$cfield.".value=path.substr(pos+1);";

}

}

if($onchangefile)

$onchangefile='onChange="'.$onchangefile.'"';

echo $function.$disp.$strtype.'
<input type="File" id="file'.$cfieldname.'" name="file'.$cfieldname.'" '.$onchangefile.'>'.$strfilename;

}

}

function my_stripos($str,$needle, $offest)

{

if (strlen($needle)==0 || strlen($str)==0)

return false;

return strpos(strtolower($str),strtolower($needle), $offest);

}
function my_str_ireplace($search, $replace,$str)

{

$pos=my_stripos($str,$search,0);

if($pos===false)

return $str;

return substr($str,0,$pos).$replace.substr($str,$pos+strlen($search));

}
function in_assoc_array($name, $arr)

{

foreach ($arr as $key => $value)

if ($key==$name)

return true;
return false;

}
function loadSelectContent($field, $value,$fvalue="")

{

global $conn,$LookupSQL,$strTableName;
$Lookup = "";

$response = array();

$output = "";
$rs=db_query($LookupSQL,$conn);
if(!FastType($field))

{

while ($data = db_fetch_numarray($rs))

{

$response[] = $data[0];

$response[] = $data[1];

}

}

else

{

$data=db_fetch_numarray($rs);

// one record only

if($data && (strlen($fvalue) || !db_fetch_numarray($rs)))

{

$response[] = $data[0];

$response[] = $data[1];

}

}

return $response;

}
function xmlencode($str)

{
$str = str_replace("&","&amp;",$str);

$str = str_replace("<","&lt;",$str);

$str = str_replace(">","&gt;",$str);
$out="";

$len=strlen($str);

$ind=0;

for($i=0;$i<$len;$i++)

{

if(ord($str[$i])>=128)

{

$out.="&#".ord($str[$i]).";";

if($ind<$i)

$out.=substr($str,$ind,$i-$ind);

$ind=$i+1;

}

}

if($ind<$len)

$out.=substr($str,$ind);

return str_replace("'","&apos;",$out);
}
function print_inline_array(&$arr,$printkey=false)

{

if(!$printkey)

{

foreach ( $arr as $key=>$val )

echo str_replace(array("&","<","\\","\r","\n"),array("&amp;","&lt;","\\\\","\\r","\\n"),str_replace(array("\\","\r","\n"),array("\\\\","\\r","\\n"),$val))."\\n";

}

else

{

foreach( $arr as $key=>$val )

echo str_replace(array("&","<","\\","\r","\n"),array("&amp;","&lt;","\\\\","\\r","\\n"),str_replace(array("\\","\r","\n"),array("\\\\","\\r","\\n"),$key))."\\n";

}
}
?>
Now, where do I put: onFocus="clearDefault(this)"

J
Jane 8/26/2008

It is dependent on format you have set up on the "Edit as" settings dialog on the Visual Editor tab.

I
iripais author 8/26/2008

I have been trying to fix my problem, but I can't see how.

The problem is that I have a few days letf to finish this project :-(
Can anyone help me?
This is an image of the form


I have 6 fields that are textfields and 2 that are texteareas
nome - text field

email as E-mail - text field (Validade as e-mail)

contacto as Telefone/Telemóvel - text field

Morada - Text area

cod1 as cod - text field

cod2 as post - text field

localidade as - text field

mensagem as - text area