This topic is locked
[SOLVED]

 Custom field and JS on load

11/28/2012 2:54:28 PM
PHPRunner General questions
W
wildwally author

I have a custom drop down created through the use of php snippet and is working - I want JS onload to see whe it changes its value and what it changed to. The normal approach is not working or i'm doing something wrong since it's a custom field.


var ctrlmenu = document.getElementById("ConSAFmenu");
ctrlmenu.on('change', function(e){

if (ctrlmenu.getValue() == 'Active Jobs')

{

alert("working 1");

}

});


C
cgphp 11/28/2012

The on method is only available for controls of PHPrunner fields. If the dropdown is not a custom field, try this code:



var ctrlmenu = Runner.getControl(pageid, "ConSAFmenu");

ctrlmenu.on('change', function(e){

if(this.getValue() == 'Active Jobs')

{

alert("working 1");

}

});
W
wildwally author 11/28/2012

it's a custom field.

W
wildwally author 11/28/2012

not sure if this was the proper way to go about doing it but this is what i did and i got the alert to pop up, so its a start.
From the PHP Snippet I created this:



$str= "<script language=\"javascript\" type=\"text/javascript\">";

$str.= "function test()";

$str.= "{ alert('Hello'); }";

$str.= "</script>";

$str.= "<select id='ConSAFmenu' onchange='test()'><option value=''>Change View</option>";

$str.="<option value='1'>Active Jobs</option>";

$str.="<option value='2'>All Jobs</option>";

$str.="<option value='3'>Current Projects</option>";

$str.="<option value='4'>Closing Date Concerns</option>";

$str.="</select>";

$value = $str;

echo $value;


Now I'll go in and add the real coding - if there is another (better) way to accomplish the same please share.

C
cgphp 11/28/2012
$("#ConSAFmenu").change(function(e){

if($(this).val() == 'Active Jobs')

{

alert("working 1");

}

});