setting hidden vars by javascript not working in Wordpress 3.3.1 admin plugin pages

222 Views Asked by At

I need to set hidden vars from within custom admin plugin page (cos postback with url query params is not allowed (permissions) in wordpress. e.g.

<script>
function change_event(invar1)
{
    document.getElementById('my_tag').onclick = function(){new_func();}
//alert (invar1);  //happiness

//Set hidden vars   //oh crap, script breaks , next alert does not alert, and hdnCmd remains blank after this
document.getElementById('hdnCmd').value=invar1; 

    alert ("hdn = " + document.getElementById('hdnCmd').value); 

     //reload the window
     //window.location.reload();
}
</script>

Thx

1

There are 1 best solutions below

1
On

Resolved.

Pointy thx, tried the register scrit, but no go. So, found a plugin which allows WP admin pages to use params in the url.

Then in another page,...this is interesting...and did not have to register scripts either. I had to use a dropdown to select the "MenuItem" eg Sandwiches, vs Pita breads, vs Salads to assign Fillings for those menu items,..I now had to use javascrit and hiddeen inputs. which turned out to be 2 pronged approach.. also using Jquery

On php side, per row of my table constructed with db data in it (edit, del,ins,updt) I set the hidden var from the url param..

$Sel = $_GET["sel"]

eg.

   foreach ($myrows as $row) 
   {        
if($row->F_Id == $_GET["recId"] and $_GET["Action"] == "Edit")  
{
$Sel = $_GET["sel"]
?>
    <input  name="Select2" id="Select2" value="<?php echo $Sel;?>" >
    <input  type="hidden" name="hdnSelect2" id="hdnSelect2" value="<?php echo $Sel;?>" > 

and the drop down (bit different as i used an associative array such that I could get the Datarow's PK and the description to display

<script> 
//use jQuery in place of hash if in WP
jQuery(document).ready(function(){ 

jQuery("#MenuItems option[value='jQuery('#hdnSelect2').val()']").attr('selected', 'selected'); 
jQuery("#MenuItems").prop("selectedindex",jQuery('#hdnSelect2').val());
var x = jQuery('#hdnSelect2').val();
jQuery("#MenuItems").val(x); 

});

</script>
<script type="text/javascript">      //From/for the Selects onchange event
function SetDDLValueOnChange (objDropDown) {
var objHidden = document.getElementById("hdnSelect");

//clean up objDropDown (ie 'this') from the dropdown's onchange event
if ( objDropDown.value.length > '1')
{   
    objHidden.value = objDropDown.value.substr(0,1);
    //alert (objDropDown.value);  //results in eg 2[2]
    objDropDown.value = objHidden.val;
}
}