How do I change the value in <p id=[value] in html - html

I've asked a version of this question before and am very grateful for the help I've got but I'm still stuck so I thought it better to ask a refined question which now gets to the nub.
I've got the code below. The idea is that the select command should choose a value (initially XA, but could be XB, XC, XD) which will then be substituted for XA in the opening <span line and cause the appropriate document.getElementById line at the end to write.
But it doesn't work as it stands. Can anyone tell me how to correct it.
<span id="XA">Change</span>
<P>
<select class="selector" onchange="document.querySelector('p').id=this.value; console.log(document.querySelector('p').id)">
<option value="XA" selected>XA</option>
<option value="XB">XB</option>
<option value="XC">XC</option>
<option value="XD">XD</option>
</select>
<p id="XA"></p>
<p id="XB"></p>
<p id="XC"></p>
<p id="XD"></p>
<script>
document.getElementById("XA").innerHTML = "Option is XA";
document.getElementById("XB").innerHTML = "Option is XB";
document.getElementById("XC").innerHTML = "Option is XC";
document.getElementById("XD").innerHTML = "Option is XD";
</script>

First I would fix your html and make sure your ids are unique then you can do the following
const span = document.getElementById('text');
document.querySelector('.selector')
.addEventListener('change', event => {
const thisValue = event.currentTarget.value; // get current value
const text = `Option is ${thisValue}`;
span.innerText = text; // change span text
document.getElementById(thisValue).innerText = text; // change p value
});
<span id="text">Change</span>
<select class="selector">
<option value="XA" selected>XA</option>
<option value="XB">XB</option>
<option value="XC">XC</option>
<option value="XD">XD</option>
</select>
<p id="XA"></p>
<p id="XB"></p>
<p id="XC"></p>
<p id="XD"></p>

Related

Dynamically show previous/next div with XQuery - recursion?

knowing community,
I want to achieve the following in short: I have a XML-file with listed pizzas inside of it (it is a kind of test file). My page has a select menu from which a user choses one pizza and the pizza size, which is then both displayed below. The content will only show up after the user has chosen. This is the function:
declare function app:showpizza2($node as node(), $model as map(*)){
let $pizza1 := request:get-parameter('selectMenu1', '')
let $size1 := request:get-parameter('size1', '')
return
for $pizza in $app:pizza//pizza
where $pizza/#id eq $pizza1
let $id := $pizza/#id
return
(<a data-key="{ $id }" class="person"><div>{ $pizza1 }</div></a>,
<div>{ $size1 }</div>)
};
With a second function I now want to build previous/next buttons which take the current shown pizza, find it inside of the XML tree and then go one step further up or down. So far I am able to show one pizza above or below with these lines:
declare function app:previousPizza($node as node(), $model as map(*)){
let $pizza1 := request:get-parameter('selectMenu1', '')
return
for $pizza in $app:pizza//pizza
where $pizza/#id eq $pizza1
let $previousPizza := $pizza/preceding::pizza[1]
return
<p>{ $previousPizza }</p>
};
The problem of course is that as a "current pizza parameter" I only take the user-chosen value from the select menu. So I guess this is a typical recursion problem because I want to have a function which always takes the current parameter after clicking on a button but I kind of really have no idea how to achieve this. Can you help out?
This is my html-file where I call these functions:
<div class="row">
<div class="col-sm-4">
<!-- form for choosing pizza -->
<form action="?">
<!-- select Pizza type -->
<select name="selectMenu1" id="pizzamenu1"
data-placeholder="Pizza wählen" style="width:150px">
<option value=""></option>
<option value="pizza1">Pizza 1</option>
<option value="pizza2">Pizza 2</option>
<option value="pizza3">Pizza 3</option>
</select>
<!-- select pizza size -->
<select name="size1" data-placeholder="Größe wählen"
style="width:150px;" onchange="this.form.submit()">
<option value=""></option>
<option value="family">Familien Pizza</option>
<option value="medium">Mittel Pizza</option>
<option value="small">Kleine Pizza</option>
</select>
</form>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<!-- showpizza2 returns chosen pizza from select menu -->
<div data-template="app:showpizza2"/>
<!-- Show previous pizza -->
<div data-template="app:previousPizza"/>
</div>
</div>
Thanks.
Since the value of the user-selected pizza comes from the html list, it is in $model. Your Xquery function for the next/prev buttons should access the $model to start where you want to.
We would need to see how you call the xquery modules in your .html files, to give you a working code sample. But the problems you describe are likely originating there.
See the documentation for Using the Model to Keep Application Data

How to change select tags value when element is deleted from array?

I have select tag which takes values from array like this
<select class="groupForArchive" ng-model="selected.country">
<option ng-selected= "{{country == selected.country}}" ng-repeat="country in countrynList" value={{country}}> {{ country.name }} </option>
</select>
when I am deleting element from array(countryList) I am setting new value to this tag like this $scope.selected.country = newValue, but in select box I am getting free space like in this pictures.
before delete country from list
after delete country from list
and when I am taking select tag's ng-model I am getting correct object but I can not see it in my select box and I don't know which item is selected.
P.S newValue is array's another item(item from countrynList)
How can I fix it ?
Update AngularJS library to latest version and make changes, presented below:
angular.module('app', []).controller('ctrl', function($scope){
$scope.countrynList = [
{name:'USA'}, {name:'Spain'}, {name:'France'}, {name:'Germany'}
]
$scope.selected = {country: $scope.countrynList[0]};
$scope.Delete = function(){
var index = $scope.countrynList.indexOf($scope.selected.country);
$scope.countrynList.splice(index, 1);
$scope.selected.country = $scope.countrynList[0];
}
})
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<div ng-app='app' ng-controller='ctrl'>
<select class="groupForArchive" ng-model="selected.country">
<option ng-repeat="country in countrynList" ng-value='country'>
{{country.name}}
</option>
</select>
{{selected.country}}
<br>
<input type='button' ng-click='Delete()' value='Delete First'/>
</div>

HTML.DropDownList not showing the selected value

Please a really need some help. I getting crazy with this one.
I'm trying to build in a page 7 Tab's with 2 DropDown's in for selecting value. The list his always the same but in each tab i have a different selected value.
Everything goes well with the first one but i can't make the second one work.
Her is my Razor code:
#Html.DropDownList("Q21_objectivos", new SelectList
(Model.Q21_ObjectivosList, "Value", "Text", Model.Q21_Objs[i - 1]),
"Seleccione um objectivo",
new
{
id = "objectivo" + i.ToString(),
#class = "form-control",
#onchange = "detectarObjectivoDuplicado( " + i + ", $(this).val() );"
})
This one is not working:
#Html.DropDownList("Q21_AvaliacaoLista",
new SelectList(Model.Q21_AvaliacaoLista, "Value", "Text", Model.Q21_Pontuacao[i - 1]),
new
{
id = "avalObjectivo" + i.ToString(),
#class = "form-control",
#onchange = "CalculaPontRes();"
})
Here is the resulting HTML:
<select class="form-control" id="objectivo1" name="Q21_objectivos" onchange="detectarObjectivoDuplicado( 1, $(this).val() );"><option value="">Seleccione um objectivo</option>
<option selected="selected" value="1">Preencher as tarefas em DotProject até ao dia 1 do mês seguinte</option>
<option value="2">Desenvolver aplicação SIADAP3</option>
<option value="3">Resolver 70% dos tickets atribuidos</option>
<option value="4">Desenvolver 2 aplicações locais em VB.net</option>
<option value="5">Desenvolver 2 aplicações locais em COBOL</option>
</select>
The resulting HTML of the not selecting dropdownlist:
<select class="form-control" id="avalObjectivo1" name="Q21_AvaliacaoLista" onchange="CalculaPontRes();"><option value="5">Superado (Pontuação 5)</option>
<option value="3">Atingido (Pontuação 3)</option>
<option value="1">Não Atingido (Pontuação 1)</option>
<option value="0">Avalie o Objectivo</option>
</select>
What can I say more... The model is loaded with the list as it's possible to see in the resulting HTML.
If you change the property name "Q21_AvaliacaoLista" to something else, the selectedvalue will work.
The property name (Q21_AvaliacaoLista) and the list of items (Model.Q21_AvaliacaoLista) cannot have the same name.
Maybe it is because of data biding of MVC...
I just made it work by changing "Q21_AvaliacaoLista" to "Q21_Avaliacao" in the DropDownList that wasn't working.
Somehow the name was making probably a conflict. I don't understand why but this way it's working.

Using Div and Hide option in simple html

I'm using html. I have to display a set of questions in a form when an option is selected from a drop down.
I already have a working script. Wen I duplicated it and edited it for my requirements its not working.
var selVal = ele.options[ele.selectedIndex].value;
for example given below is the list from the dropdown. When option 1 is selected it should display a set of questions and when option 2 is selected it should display a diff set of questions.
<div id='q1'>
<b> Where is the caller from ? </b>
<select id="category" onChange="selDivision(this)">
<option value="1">Store</option>
<option value="2" >Office</option>
</select>
<br />
<br />
All the form contents are displayed instead of my requirements.
First should display only the dropdown,once selected an option the question set has to be display below.
I using simple js scripts for use as backend.
Requiring further assistance on this.
part of code that is for the hide and display function
$(document).ready(function(){
//init();
//$("#q1b").hide();
$("#1q").hide();
$("#2q").hide();
$("#3q").hide();
$("#4q").hide();
$("#5q").hide();
$("#6q").hide();
$("#7q").hide();
$("#8q").hide();
$("#9q").hide();
$("#10q").hide();
$("#1a").hide();$("#1b").hide();$("#1c").hide();$("#1d").hide();$("#1e").hide();$("#1f").hide();$("#1g").hide();
$("#2a").hide();$("#2b").hide();$("#2c").hide();$("#2d").hide();$("#2e").hide();$("#2f").hide();$("#2g").hide();
setDisabled('q1',false);
setDisabled('1q',false);
setDisabled('2q',false);
setDisabled('3q',false);
setDisabled('4q',false);
setDisabled('5q',false);
setDisabled('6q',false);
setDisabled('7q',false);
setDisabled('8q',false);
setDisabled('9q',false);
setDisabled('10q',false);
clear_form_elements(document.getElementById('test'));
});
function selDivision(ele)
{
var selVal = ele.options[ele.selectedIndex].value;
if(selVal == "1")
{
$('#1q').show(); setDisabled('q1',true);
$("#1a").show();$("#1b").show();$("#1c").show();$("#1d").show();$("#1e").show();$("#1f").show();$("#1g").show();
}
if(selVal == "2" )
{
$('#2q').show(); setDisabled('q1',true);
$("#2a").show();$("#2b").show();$("#2c").show();$("#2d").show();$("#2e").show();$("#2f").show();$("#2g").show();$("#2h").show();$("#2i").show();
}
Val=selVal;
}
</script>
</head>
q1 q2 are the questions fro drop down
The other variables are the questions under the option.
Try like this
<div id='questions' style="display:none">
<div id='q1' style="display:none">
<b> Question 1? </b>
<b> a. ans1</b>
<b> b. ans2</b>
<b> c. ans3</b>
</div>
<div id='q2' style="display:none">
<b> Question 2 ? </b>
<b> a. ans1</b>
<b> b. ans2</b>
<b> c. ans3</b>
</div>
</div>
<select id="category">
<option value="0">-select-</option>
<option value="1">Store</option>
<option value="2" >Office</option>
</select>
<br />
<script>
$('#category').on("change",function() {
//Hide all Questions in first time
$('#questions div').hide();
//get selected value
var id=$('#category').val();
//display
$('#questions').show();
$('#q'+id).show();
});
</script>
Here working example http://jsfiddle.net/d1udL1cr/

Zope (Page Template), Ajax/Javascript and MySQL

I have 2 chained list :
<select>
<option> Half Life </option>
<option> Mario </option>
...
</select>
<select>
<option> Gordon </option>
<option> Alexia </option>
<option> Peach </option>
<option> Luigi </option>
...
</select>
These selects are populated by MySQL requests (ZSQL Method)
I would like to load this second form only when it's necessary. I don't know how to do in a Zope Page Template to link these select dynamically (Certainly with AJAX and JAVASCRIPT?). So I search in some topics but I don't find examples..
(I find these topics, but I don't know how to operate : dynamicly fill table using zpt and ajax as update; http://play.pixelblaster.ro/blog/topics/AJAX ; http://zajax.net/)
Thanks in advance !
1) in the form page:
$("#first_select").click(function(){
var dat_game = $('#first_select option:selected').text();
$.post("a_new_page_template", { dat_game: dat_game},
function(data){
var $response=$(data);
var res = $response.filter('#whatiwant').html();
$('#second_select').append(res);
});
return false;
});
2) in the 'a_new_page_template':
<html>
<body tal:define="results here/sql_select_value;
start request/start|python:0;
batch python:modules['ZTUtils'].Batch(results,
size=50,
start=start)">
<span id="whatiwant">
<tal:x repeat="result batch">
<option><tal:x replace="result/value">value goes here</tal:x></option>
</tal:x>
</span>
</body>
</html>
Thanks to me :)