Textbox and variables javascript and HTML - variables

I want to set two JavaScript variables as the values of these textboxes.
Can anyone can help me?
<form name="myform1">
<input type="number" name="pop_size" value="3">
<input type="button" value="Pop Size" id="population" onclick="setValue()">
</form>
<form name="myform2">
<input type="number" name="totalIterations" value="2">
<input type="button" value="Iterations" id="Iterations" onclick="setValue()">
</form>

You can use getElementsByName() to get a list of elements by their names in the form. Since your names are unique (which isn't necessary in the spec, but is a good idea for this exact reason), the array returned by that function should have exactly one element in it. Something like this:
var firstVariable = document.getElementsByName('pop_size')[0].value;
var secondVariable = document.getElementsByName('totalIterations')[0].value;
Or did you mean that you want to set the values to what's in a variable? That would be the reverse:
document.getElementsByName('pop_size')[0].value = firstVariable;
document.getElementsByName('totalIterations')[0].value = secondVariable;

Related

vuejs v-validate custom validation rule: max value must bigger than min value that user input

Below are my code for 2 input fields in vuejs. The current validation rule is they both need to be numeric. I've read the official document here.
I need to add another rule, that max-amount must be bigger than min-amount. The trick is min-amount is user input, not pre-determined. How should I implement this customize validator?
<div class="min-section">
<label>Min</label>
<input type="text"
class="uk-input"
name="min-amount"
v-validate="'numeric'"
v-model="minAmount" />
</div>
<div class="max-section">
<label>Max</label>
<input type="text"
class="uk-input"
name="max-amount"
v-validate="'numeric'"
v-model="maxAmount"/>
</div>
You could bind min_value in the v-validate rules of the max-amount <input>:
<input name="min-amount" v-model="minAmount">
<input name="max-amount"
v-validate="'numeric|min_value:' + minAmount"
v-model="maxAmount">
demo
Also note if you don't have a specific reason to use a text input, you should consider using <input type="number"> (instead of <input type="text">) so that the user could only enter numeric values.

Binding View-Models with collection properties

My view model has a sole property, currentProject, which itself has a child property that is an array of strings. When I bind everything to the view, all the data populates correctly including the array of strings. When I edit the data, the array of strings is not updated.
Is there something specific I have to do here to make this a two-way binding? I tried the the two-way command but it made no difference.
My View Model looks like this:
export class Edit {
currentProject;
...
}
CurrentProject gets set to an instance of the project class:
export class Project {
id = '';
name = '';
modifiedDate = '';
createdBy = '';
students = [];
}
My edit view looks like this:
<template>
<section>
<h1>Edit ${currentProject.name}</h1>
<form role="form" submit.delegate="save()">
<label for="name">Project Name</label>
<input type="text" maxlenth="100" id="name" value.bind="currentProject.name" />
<h2>Students</h2>
<div repeat.for="student of currentProject.students">
<label for="name${index}">Student ${$index + 1}</label>
<input type="text" maxlenth="100" id="name${$index}" value.bind="student" />
</div>
<button class="btn">Add Student</button>
<button type="submit" class="btn btn-primary">Update project</button>
</form>
</section>
</template>
Any help would be greatly appreciated. I suspect I am missing some minor detail.
Thanks,
Andrew
Looks like the issue here is due to strings (primitive type) immutability, there is no reference between string you are editing in input field and the one in the array, it's just two different copies.
That being said, there are two approaches you can take to make it work properly. The best one is to have array of object for students, maybe like this:
[{name: 'Tomas Mann'}, {name: 'Alex Bloom'}]
then repeat.for part would look like:
<div repeat.for="student of currentProject.students">
<label for="name${index}">Student ${$index + 1}</label>
<input type="text" maxlenth="100" id="name${$index}" value.bind="student.name" />
</div>
This data structure is also more flexible. For example, you can add additional student information like age, score, etc. You could even have students array to be an array of Student objects students: Student[], etc.
If you still want to use array of simple strings then you could do this:
<div repeat.for="student of currentProject.students">
<label for="name${index}">Student ${$index + 1}</label>
<input type="text" maxlenth="100" id="name${$index}" value.bind="$parent.currentProject.students[$index]" />
</div>

Not able to get Xpath post applying starts with

My HTML Structure:
<form id="assignment-submission-540296" action="/assignments/submit-assignment" enctype="multipart/form-data" method="POST">
<input id="assignment_id" type="hidden" value="540296" name="assignment_id">
<input id="assignment_user_id" type="hidden" value="131639273" name="assignment_user_id">
<input type="hidden" value="/assignments/view/540296/131639273" name="returnUrl">
<div style="margin-right:230px;margin-top:-2px">
<input class="by-button fileuploadImage" type="button" value="Submit" data_id="" style="margin-left:155px">
My XPATH Generated with FIREPATH Is this:
.//*[#id='assignment-submission-540296']/input[4]
in the above x path 540296 is dynamic value hence I did something like this. Modified XPATH:
.//*[starts-with(#id,'assignment-submission']/input[4]
but after this not able to identify the element.
You are just missing a closing parenthesis:
.//*[starts-with(#id,'assignment-submission')]//input[4]
HERE ^
Also, you needed to use // after finding the form to search for desired input anywhere inside the form.
Besides, you can make the xpath a bit more specific by specifying a form tag and relying on input type:
.//form[starts-with(#id,'assignment-submission')]//input[#type="button" and #value="Submit"]

Can Angular Filter Input

Is there a way to filter through inputs in Angular? I'd Imagine
var input = e.$filter(/a-zA-Z/);
I'm not sure to understand your question, but you can force a pattern on an input with the ngPattern directive.
<form name="theForm" novalidate>
<input type="text" ng-model="foo" ng-pattern="/a-zA-Z/" required/>
<button ng-click="update()" ng-disabled="theForm.$invalid">SAVE</button>
</form>

way to store POST variables when using django

with a form am searching schools nearby and displaying them as table.
inside views.py
def method1:
printquery = request.POST.copy()
zip = printquery['zip']
if not zip:
city = printquery['city']
state = printquery['state']
zip = getZip(city,state)
results = zipObj.getSchools(zip);
render_to_response('some.html',{'results':results,'query':printquery,})
inside template
<form id="print-search" target="_blank" action="" method="post" name="print">
<input type="hidden" value="{%if query%}{{query}}{%endif%} name="query"/>
<input type ="submit" value="Print the Results" name="submitPrint"/>
</form>
<table>
{% block xxx%}displays schools result {%endblock%}
</table>
when the "Print the results" button is clicked.I want to use 'query',
do the search again and print in separate page[I have no choice of storing in session id].
Problem am facing is, {{query}} is a turing to a string i.e.,u"{'zip': u'76123'"} on which i cannot do something like query['zip'],
Is there a way to solve this. Ideas are most welcome.
Instead of taking the whole dictionary as value, do something like this
<form id="print-search" target="_blank" action="" method="post" name="providerprint">
<input type="hidden" value="{%if query.zip %}{{query.zip}}{%else%}""{%endif%}" name="zip"/>
<input type="hidden" value="{%if query.city %}{{query.ciyt}}{%else%}""{%endif%}" name="city"/>
<input type="hidden" value="{%if query.state %}{{query.state}}{%else%}""{%endif%}" name="state"/>
<input type ="submit" value="Print this Search" name="submitProviderprint"/>
</form>
inside the views.py we can access this as
zip = params['zip']
city = params['city']
state = params['state']
and it worked for me.:)