Get Field Value Edit Page

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
yeico
User
Posts: 20

Get Field Value Edit Page

Post by yeico »

Hi all. I have 2 problems. On add page i hide some fields conditionally using change function in startupscript, and all its allrigth. For example:

$("input[name='x_ajuste_valor_inicial']").change(function() {
if (this.value !=1) {
$(this).fields("nvo_valor_liquidacion").visible(false);

Now, in edit page i want to use the same schema, but some of those hiding fields depending for value to the other one. So i need get the value of some fields when edit page load.

I tried testing with:
if
( $("#x_id_detalle_estado").val() == "1")
{
something
};

Does not work, field is dropdown list.

and

alert(

$("#x_id_detalle_estado").val()); Doesnt return nothing

alert($("#x_id_detalle_estado").text()); return "Please Select" text --> After alert the value of dopdrownlist load , i dont know..

alert($(this).fields("id_detalle_estado").value); nothing happens

How can i get the value of field in edit pages for my startupscript ???

The second problem is that some of that fields are readOnly for some users. This could be change the method to get that values or is the same thing?

Thanks in advance for any help.

Regards.


sangnandar
User
Posts: 980

Post by sangnandar »

yeico wrote:
alert($("#x_id_detalle_estado").val()); //return nothing
Looks good, can't tell what's wrong.

But try this:
var myVal = $("#x_id_detalle_estado").val();
if (myVal == '1') {
// do something
}
console.log(myVal); //console.log() is better than alert() for debugging, just saying. To check the value use browser F12 -> Console.

yeico wrote:
alert($("#x_id_detalle_estado").text()); //return "Please Select" text --> After alert the value of dopdrownlist load , i dont know..
I'm guessing the empty (Please Select) load first before dropdrownlist load. You can see when Edit Page load it needs time for ewlookup.php to load. Before that load finish it sets empty to the lookup value, hence .text() = "Please Select". Also note that alert() freeze the browser window (another reason why console.log() is better).

yeico wrote:
alert($(this).fields("id_detalle_estado").value); //nothing happens
Sure. Your $(this) has no context. $(this) should always have context.

yeico wrote:
The second problem is that some of that fields are readOnly for some users. This
could be change the method to get that values or is the same thing?
Should be the same thing.


I have this code in my apps, might be handy for you.

Behavior:
fieldA dropdown value decide either field1 or field1 is shown.

Setting:
fieldA -> Field Setup -> Client-side Events
{"change": function(e) {
var $row = $(this).fields();
var myVar = $row["<fieldA>"].value();
if (myVar == 1) {
$row["<field1>"].visible(true);
$row["<field2>"].visible(false);
$row["<field2>"].value(new String(''));
}
if (myVar == 2) {
$row["<field1>"].visible(false);
$row["<field1>"].value(new String(''));
$row["<field2>"].visible(true);
}
}}

Edit Page -> Startup Script
var myVal = $("#x<fieldA>").val();
if (myVal == '1') $("#r
<field2>").hide() else $("#r_<field1>").hide();


yeico
User
Posts: 20

Post by yeico »

Thanks for your reply. To get the value you need put an empty onchange function before call the value. The other side that does not work. Thanks for your help.

$(document).ready(function()
{

$("#x_id_detalle_estado").change(function()
{ });

});

var myVal = $("#x_id_detalle_estado").val();

console.log(myVal);


Post Reply