This topic is locked

Field fillup with a default value

2/14/2008 10:50:40 AM
PHPRunner General questions
R
rainerwolf author

Hi,
what can i do, when i want to setup a field with a default value:
Example: i have a field named surname1, and i want (add and edit Record function) that the field1 surname2 is filled with the value from surname1.
I have tested in the before record added it with: $values["surname2"]=ucfirst($values["surname1"]);
After the record is added i see the correct value with the list function, but i don't see the value from field surname2 when i am in the add record function.
Please Help

C
comlan 2/14/2008

Sounds like the question I asked yesterday and was answered by Jane and works great.
See my recent post "Inserting default values from another table on "Add New".
Should do the trick.

R
rainerwolf author 2/15/2008

Sounds like the question I asked yesterday and was answered by Jane and works great.

See my recent post "Inserting default values from another table on "Add New".
Should do the trick.


Thank you very much for Help. It works great.

Rainer

R
rainerwolf author 2/15/2008

It Works great, when i read values from another table.
But when i use values in my add form following happend:
Example: i have a field named surname1, and i want, that the field1 surname2 is filled with the value from surname1.
I have tested in the before record added it with: $values["surname2"]=ucfirst($values["surname1"]);
After the record is added i see the correct value with the list function, but i don't see the value from field surname2 when i am in the add record function.

J
Jane 2/15/2008

Hi,
to fill surname2 field dynamically on the add page use JavaScript code on the Visual Editor tab.

Here is a sample:

{literal}<script>

document.forms.editform.value_surname2.onclick=function()

{

document.forms.editform.value_surname2.value=document.forms.editform.value_surna

me1.value;

}

</script>{/literal}

R
rainerwolf author 2/15/2008

Hi,

to fill surname2 field dynamically on the add page use JavaScript code on the Visual Editor tab.

Here is a sample:


Hi Jane,
i put the Text in my add Record section as follows:
global $conn;

$values["Familienname"]=ucfirst($values["Familienname"]);

$values["Vorname"]=ucfirst($values["Vorname"]);

$values["Geburtsname"]=ucfirst($values["Geburtsname"]);

$values["Strasse_und_Hausnummer"]=ucfirst($values["Strasse_und_Hausnummer"]);

$values["Geburtsort"]=ucfirst($values["Geburtsort"]);

//$values["Erz1Familienname"]=ucfirst($values["Erz1Familienname"]);

$values["Erz1Vorname"]=ucfirst($values["Erz1Vorname"]);
{literal}<script>;

document.forms.editform.value_Erz1Familienname.onclick=function()

{

document.forms.editform.value_Erz1Familienname.value=document.forms.editform.val

ue_Familienname.value;

}

</script>{/literal};
$str = "select jahr from swh_jahre";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$values["jahr"] = $data["jahre"];
and i got an error like this:
Parse error: syntax error, unexpected '}' in /var/www/vhosts/test/subdomains/ks-bb/httpdocs/bs/surname-test/include/surname-test_events.php on line 35
Can you say me, what is wrong?
Rainer

J
Jane 2/18/2008

Rainer,
add JavaScript code on the Visual Editor tab -> HTML mode, not to one of your events.