This topic is locked

check the content of a field on the fly

5/21/2008 3:19:13 AM
PHPRunner General questions
R
rainerwolf author

Hi,
i want to ask, if it is possible, to navigate in an add/edit form, when the content of an input field has a defined value.
I have a table with the following fields:
name, surname, street, city, teaching_subject , teaching_subject1, teaching_subject2, teaching_subject3, teaching_subject4, teaching_subject5, course, course1, course2, course3.
The task is:
A pupil wants to reserve some teaching_subjects and courses in a school and it is required, that he must pick an teaching_subject with english, and another teaching_subject with mathematics. After this, he must pick up another teaching_subject with another foreign language (for example german, french, spanish), but only one of this. Then, he must pick up some courses, (chemical, biology, geography, music, religion) 2 of them are required, and 2 courses are optional.
For example:
A pupil filles out the the first fields teaching_subject with english and teaching_subject1 with mathematics and teaching_subject1 with german. After this the fields teaching_subject2, teaching_subject3 and teaching_subject4 must skipped to the field course with chemical.
I hope, you understand my problem.
Rainer

J
Jane 5/21/2008

Rainer,
use custom JavaScript to manage fields on the add/edit page:

http://www.asprunner.com/forums/index.php?showtopic=6504

R
rainerwolf author 5/21/2008

Hi Jane,
i put this code in visual editor html:
{literal}

<script language="JavaScript" type="text/javascript">
document.forms.editform.value_anschrift_ort.onchange=function()

{

if(this.options[this.selectedIndex].value=='CO')

document.forms.editform.value_anschrift_ortsteil.disabled=false;

else

{

document.forms.editform.value_anschrift_ortsteil.disabled=true;

document.forms.editform.value_anschrift_ortsteil.value='';

}

}

{/literal}
</script>
And when i change it in edit mode to another value like 'AL' it works and it skips anschrift_ortsteil.

But now i go back to the field anschrift_ort and make the choice to 'CO', and now it skips again anschrift_ortsteil.

Did you have a solution for this problem?
And another question, is it possible to put this code in Phprunner events and not directly in the html code?
Thanks, Rainer

J
Jane 5/22/2008

Rainer,
I recommend you to add JavaSvript code to the page directly.
To debug your code check this.options[this.selectedIndex].value before:

document.forms.editform.value_anschrift_ort.onchange=function()

{

alert(this.options[this.selectedIndex].value);

if(this.options[this.selectedIndex].value=='CO')

document.forms.editform.value_anschrift_ortsteil.disabled=false;

else

{

document.forms.editform.value_anschrift_ortsteil.disabled=true;

document.forms.editform.value_anschrift_ortsteil.value='';

}

}

R
rainerwolf author 5/22/2008

Hi Jane,
thanks for the hint, everything looks right.
I think, i don't have correctly explained my problem:
at he beginning the dropdown field anschrift_ort has the value CO and i can select the dropdown field anschrift_ortsteil. --> ok
When change the dropdown field anschrift_ort in Edit record to another value like 'AL' it works and it skips the dropdown field anschrift_ortsteil. --> ok
But now i go back in my form Edit record to the dropdown field anschrift_ort and select 'CO' again, and now it skips again anschrift_ortsteil. --> not ok, because the field has the value 'CO' and i want to select now the dropdown field anschrift_ortsteil.
Hope, you understand me.
Rainer

J
Jane 5/22/2008

Rainer,
I can't check your code without actual files.

You can publish your project on the Demo Account and send a URL to your pages to support@xlinesoft.com.

R
rainerwolf author 5/22/2008

Rainer,

I can't check your code without actual files.

You can publish your project on the Demo Account and send a URL to your pages to support@xlinesoft.com.


Jane,
thank you very much, i put the code above for other members:
{literal}

<script language="JavaScript" type="text/javascript">

document.forms.editform.value_anschrift_ort.onchange=function()

{

alert(this.options[this.selectedIndex].value);

if(this.options[this.selectedIndex].value=='Colorado')

document.forms.editform.value_anschrift_ortsteil.disabled=false;

else

{

document.forms.editform.value_anschrift_ortsteil.disabled=true;

document.forms.editform.value_anschrift_ortsteil.value='';

}

}

</script

{/literal}

R
rainerwolf author 6/9/2008

Hi Jane,
It works great on an dropdown field, but i have tested this procedure again on an normal text field. (name=comment)

At the beginning the field is empty and after typing some text, i got no alert:
{literal}

<script language="JavaScript" type="text/javascript">

document.forms.editform.value_comment.onchange=function()

{

alert(this.options[this.selectedIndex].value);if(this.options[this.selectedIndex].value=='')

document.forms.editform.value_comment.disabled=false;

else

{

document.forms.editform.value_comment.disabled=true;

document.forms.editform.value_comment.value='';

}

}

</script

{/literal}
Please can you tell me, what is wrong?

Rainer

J
Jane 6/10/2008

Rainer,
here is the correct code:

{literal}

<script language="JavaScript" type="text/javascript">

document.forms.editform.value_comment.onchange=function()

{

alert(document.forms.editform.value_comment.value);

}

</script

{/literal}

R
rainerwolf author 6/10/2008

Hi Jane,
thank you for this solution.
Now i want to check, i comment is filled out and then set another field on disable. I tried this:
{literal}

<script language="JavaScript" type="text/javascript">

document.forms.editform.value_comment.onchange=function()

{

alert(document.forms.editform.value_comment.value);

if(document.forms.editform.value_comment.value=='')

document.forms.editform.value_name.disabled=false;

else

{

document.forms.editform.value_name.disabled=true;

document.forms.editform.value_name.value='';

}

}

</script>

{/literal}
But nothing happened, only the alert function will display the value, but the name field is not skipped.
Another question:
Is it possible with javascript to check at the beginning of the form, if input fields are empty and display warnings in the form like this:
name: please enter your name

surname:
please enter your surname

comment: please enter your comment
and after that, when name is filled, the warning wille be show as following:
name:
ok

surname: please enter your surname

comment:
please enter your comment
and after that, when surname is filled, the warning wille be show as following:
name: ok

surname:
ok

comment: please enter your comment
and after that, when comment is filled, the warning wille be show as following:
name:
ok

surname: ok

comment:
ok
Best regards
Rainer

R
rainerwolf author 6/12/2008

Hi Jane,
My question about the following function is done, it works as follows:
{literal}

<script language="JavaScript" type="text/javascript">

document.forms.editform.value_comment.onchange=function()

{

alert(document.forms.editform.value_comment.value);

if(document.forms.editform.value_comment.value=="")

document.forms.editform.value_name.disabled=false;

else

{

document.forms.editform.value_name.disabled=true;

document.forms.editform.value_name.value='';

}

}

</script>

{/literal}
Is it possible with javascript to check at the beginning of the form, if input fields are empty and display warnings in the form like this:
name: please enter your name

surname:
please enter your surname

comment: please enter your comment
and after that, when name is filled, the warning will be show as following:
name:
ok

surname: please enter your surname

comment:
please enter your comment
and after that, when surname is filled, the warning will be show as following:
name: ok

surname:
ok

comment: please enter your comment
and after that, when comment is filled, the warning will be show as following:
name:
ok

surname: ok

comment:
ok
Best regards
Rainer

J
Jane 6/17/2008

Rainer,
sure you can do it.

Try to change your actual JavaScript code and add another onchange() events.

I recommend you to check some JavaScript articles and tutorials here:

http://www.w3schools.com/js/default.asp

http://www.pageresource.com/jscript/