• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 480
  • Last Modified:

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

$yesOrNo='yes'
//$yesOrNo='no'
$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


if $yesOrNo='yes' then

<h3>Value:<span id="yesOrNo">'.$yesOrNo.'</span></h3>

<h3>Value:<span id="yesOrNo">yes</span></h3>

then there is a select menu
change value
yes
no

user is given option to change yes into yes

I want
change value
no



without doing
if $yesOrNo='yes'
selectOptions="no:no"
else
selectOptions="yes:yes"
0
rgb192
Asked:
rgb192
  • 4
  • 3
1 Solution
 
Mark BradyCommented:
What? That is very confusing. There are parts of your question that don't make sense.

user is given option to change yes into yes
Why would they need to change 'yes' to 'yes' ? that is not a change.

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

So you want to change the value inside your <h3> tags but you do not want to use an if/else statement?

Perhaps if you can be a bit more specific and clear about what you have and what it is exactly that you want to happen when a user changes options in your select box. Also, what does 'yes:yes' and 'no:no' mean ? If you are referring to the value in a select box then you simply say 'yes' and 'no' is the options.

If this is a javascript thing you are looking for then it would be this.

<script type="text/javascript">
function updateHeader(val) {
    if (val != '') {
        document.getElementById('yesOrNo').innerHTML = val;
    }
}
</script>

And your select box would be something like...

<select name='choice' onchange='updateHeader(this.value)'>
<option value='no'>No</option>
<option value='yes'>Yes</option>
</select>

Now when a user changes the option in the selectbox it will change the text in the <span></span> element without the need for an if/else statement. Not sure if that is what you want but it's the best I can do with how this question is presented to us.
0
 
rgb192Author Commented:
>>Why would they need to change 'yes' to 'yes' ? that is not a change.


I do not want user to change <h3>yes</h3> to yes
0
 
Mark BradyCommented:
I do not want user to change <h3>yes</h3> to yes

What is it that you do want then? Did you read my comments? There were a few questions in there. I can't offer any help unless you make yourself clear about what you want, we can't just guess at the answer.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rgb192Author Commented:
>>Also, what does 'yes:yes' and 'no:no' mean

display value yes,
stored value yes



>>
<script type="text/javascript">
function updateHeader(val) {
    if (val != '') {
        document.getElementById('yesOrNo').innerHTML = val;
    }
}
</script>

And your select box would be something like...

<select name='choice' onchange='updateHeader(this.value)'>
<option value='no'>No</option>
<option value='yes'>Yes</option>
</select>



I do not understand what these do
0
 
Mark BradyCommented:
Copy the following code and paste it into a new document (empty page).
Save it as test.html
Open your browser and point to the new file (load it just like any other web page)
Look at what is on the page.

You will see a select element (dropdown select box with choices for the user)
An <h2></h2> heading element with some text in it (default text).


Do this:  Make a selection from the dropdown select box.
Look at the <h2></h2> text, it changes depending on what you select.

<html>
<head><title>Test</title>

<script type="text/javascript">

function updateHeader(val) {
    if (val != '') {
        document.getElementById('yesOrNo').innerHTML = val;
    }
}
</script>

</head>
<body>
Please make a choice : 
<select name='choice' onchange='updateHeader(this.value)'>
	<option selected value='Please make a choice'>Make a choice</option>
<option value='No'>No</option>
<option value='Yes'>Yes</option>
</select>
<br><br>
Your choice is <h3 id='yesOrNo'>Not Choosen</h3>
</body>
</html>

Open in new window


All the best.. I'm done
0
 
rgb192Author Commented:
this is a good solution to onchange the h2 value
and it works without jquery

thank you
0
 
Mark BradyCommented:
Yes it uses javascript onlt. No need to use anything else. Most page elements have events that can be fired when a user manipulates them. Javascript can capture those events and act upon them. For exampale, when you make a selection from a <select></select> element, it fires the onChange() event for that element. All we are doing is saying to to DOM or webpage then when this event is fired I want you to run the javascript function that is named in the onChange() event. Ie:  onChange="updateHeader(this.value)"

this.value is the value that is stored in the select elements currently selected "value" field.
Pretty simple really.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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