[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1135
  • Last Modified:

jquery editInPlace select_options shows repeats if I put the default value first (follow up question)

jquery editInPlace select_options shows repeats if I put the default value first


if $yesOrNo='yes' then
select_options=
yes
yes
no

if $yesOrNo='no' then
select_options=
no
yes
no



without doing
if $yesOrNo='yes'
selectOptions="no:no"
else
selectOptions="yes:yes"

is there a way to eliminate repeats



note: a callback function provided by expert Hielo will

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27857043.html


 not work in this example because the form is being processed on another page

                url: "packages.php",
                params: "a=renamepackage&pid=1",


this is the solution provided by Hielo
$savingText="saving....";
$selectOptions="yes,no";
        echo '<h3>Value:<span id="yesOrNo">'.$yesOrNo.'</span></h3>';
        echo '<script type="text/javascript">
                    $(document).ready(function(){
                        $("#yesOrNo").editInPlace({
                            "saving_text": "'.$savingText.'",
                            "field_type": "select",
                            "select_options": "'.$selectOptions.'"
                            ,"callback": function(element_id, selectedValue, originalText) { 
								return selectedValue;
							}
                        });
                    });
                </script>';

Open in new window





$savingText="saving....";
$selectOptions="yes:yes ,no:no";
        echo '<h3>Value:<span id="yesOrNo">'.$yesOrNo.'</span></h3>';
        echo '<script type="text/javascript">
                    $(document).ready(function(){
                        $("#yesOrNo").editInPlace({


                url: "packages.php",
                params: "a=renamepackage&pid=1",

                            saving_text: "'.$savingText.'",
                            field_type: "select",
                            select_options: "'.$selectOptions.'"
                        });
                    });
                </script>';

Open in new window

0
rgb192
Asked:
rgb192
2 Solutions
 
Kyle HamiltonData ScientistCommented:
you can do what you are asking, but you would have to edit the actual plugin. do you want to do that?

The first option is hardcoded to be un-editable in the plugin script. You would need to remove that. Then you set your defualt option to : "yes", and only use "no" as your other options. i haven't tested it, so there may be other things you need to do too...
0
 
hieloCommented:
not work in this example because the form is being processed on another page

                url: "packages.php",
                params: "a=renamepackage&pid=1",
OK, then in this case, the seconds snippet of code you posted is exactly what you need.  NOTE: You need the callback only if you are NOT processing on the server.  But in this case, since you provided a URL, the data is sent to the server via a POST request. Thus, what you need to do is send the  updated value from the server:

<?php
//packages.php
//this variable is meant to track errors.  
//Initializing it to null indicates that there have been no errors.
$err=null;

//here $_POST['update_value'] will contain the new selection (yes or no)
//so if you need to update some db record you do it here.  Be sure
//to update the $err variable in case of errors
//...

//then send back the update_value if  were are no errors
if( is_null($err) )
{
           echo $_POST['update_value'];
}
else  //otherwise send back the original value
{
          echo $_POST['original_value'];
}
exit;
0
 
rgb192Author Commented:
thanks

I have a follow up question

want user to be given option to change value to a new value

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27858595.html
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now