I have a newbie question in php
When I Select value from dropdown
automated that the value is output in the textbox
for example..
<select></select>
<option>John</option>
</select>
When i select john
automatic
the information of john output on a textbox
How to do this?
thanks in advance..
Sorry for my bad english
You're speaking of something that is typically done on the client side via javascript. PHP on the other hand is a server side scripting language.
If the information about John is stored in a database somewhere you would be doing an ajax call to a php function that retrieves and returns your desired information from the database. You would then use javascript to manipulate the DOM to insert the returned information into your textbox.
I hope this helps and gets you on the right path.
This question is not in php scope, you just need some Javascript to do it:
WORKING DEMO
HTML:
<select id="cbxName">
<option value="Join">John</option>
<option value="TrungDQ">TrungDQ</option>
</select>
<input id="txtName" type="text" value=""/>
Javascript:
var e = document.getElementById("cbxName");
e.onchange = function() {
var strName = e.options[e.selectedIndex].value;
document.getElementById("txtName").value = strName;
}
Related
I'm developing in Angular.
I'm trying to save part of a JSON in a variable inside a function called in an HTML file:
<select id="postazione" onchange="postazioneSelezionata()">
<option value="" selected disabled >Scegli una postazione</option>
<option *ngFor="let postazione of postazioniNome" value="{{postazione}}">{{postazione}}</option>
</select>
(the onchange="postazioneSelezionata()").
it seems works, because if I try to print the value I'm interested in inside the console.log, it is shown correctly.
postazioneSelezionata(){
this.postazione = document.getElementById("postazione").value;
console.log(this.postazione);
}
inside the function i'm also trying to show this in the terminal:
console.log(this.fileJson.ricette[this.postazione]);
Here comes the problem...
If i try to show the part of the JSON this.fileJson inside the console.log(), it return me an error:
ERROR TypeError: Cannot read property 'ricette' of undefined
at HTMLSelectElement.postazioneSelezionata [as __zone_symbol__ON_PROPERTYchange] .
i've tried to show it in another function (not called from an html onchange event)
this.postazione = "GRIGLIA";
console.log(this.fileJson.ricette[this.postazione])
and it works... this code (called in another function) show me the portion of the fileJson JSON i'm trying to obtain
Possibly this post will be of help.
Additionally, even though you say your onchange works, the standard syntax for such events with Angular, as m.akbari mentioned in his comment, is (change):
<select id="postazione" (change)="postazioneSelezionata()">
...
</select>
And from there, unless you're not particularly bothered about the value of the change and just care to know that something was changed, you would probably pass the value in that changed...
<select id="postazione" onchange="postazioneSelezionata($event.target.value)">
...
</select>
Similar changes, syntax-wise, in your options for entering your value:
<option *ngFor="let postazione of postazioniNome" [value]="postazione">{{postazione}}</option>
Input/output binding, two-way binding, event binding... all are fairly integral to Angular, it's worth getting them figured out.
Again, see the post linked at the top for a more rounded answer and examples to using selects with Angular.
I need to validate a Promo Code for one of my html Booking form field. If the entered promo code is correct, users can submit the Booking details. Only one unique promo code. Something like "15OFFNOW" How should I do it? Please help.
Thanks.
First, don't put the promo code in your page. Anyone can see it.
I would do this, but it depends on actually functionality.
Do client side check (this can be bypassed by a malicious user)
Do server side check
Do client side check
Use a good non-reversible hashing algorithm and verify what you have in the prom text box to the hash you have stored in a JavaScript variable or in a data-hash attribute.
So if hash(text box value) == valueOf(data-hash), then proceed to sever validation.
Do server side check
In server no need of hash. Just check the post string with the promo code you have.
i try your code
<form method="post">
<input class="form-control form-control-light bdr-2 rd-0" required
data-label="Promo Code"
data-msg="Please enter a valid promo code."
type="text" name="promo-code"
placeholder="Promo Code"
pattern="15OFFNOW" required>
<input type="submit" value="submit"/>
</form>
validation is work . show this message .
You can use Javascript for that , I fyou want to match promocode or you can validate it at backend using any backend language like PHP or java
for JQuery
//previous Ajax code here
if($("#input_id").val() !== "15OFFNOW"){
return false ;
}
// here you can proceed for Ajax request
You are looking for an input pattern, also called regexp (though I would instead suggest doing it js way (but not global) or on server side as advanced users can simply inspect html code). Most probably something like this
<input type="text" name="promo" pattern="15OFFNOW" required >
Also, please try googling it, there're similar questions like this answered also on StackOwerflow, e.g.
html: Can we match an exact string using html pattern attribute only?
js & php: check if input value not equal to integer then don't submit form
I am trying to pass a variable from my classic asp page to ssrs. When I put in a literal value for the parameter, such as 296, it works fine. But I want to put in a variable that is sent by the URL so that it works in different ways for different people who are logged in. So, instead of a URL that is http://servername.net/reportserver....rs:Command=Render&Agency=296 (for the agency that is number 296) I want to use a variable that I have set to the agency of the person who has logged in. Let's say the variable is pAgency. I have tried Agency=" #pAgency (I set pAgency = to the logged in person's agency) and all sorts of other combinations, and have searched the web, but find no answer for this. I've even tried session variables but, no go. You must be able to do this but...
Thanks for any help you can give. Cheers!
That is not how a rest URI works to my knowledge. You need to build the string and present it first fully formed, not define a variable on it. You could do somthing in code like (using HTML Form as a base)
In the example below there are four clear things to understand:
A. The 'action' in the form must be the webservice location of a report and do a post to self. (Or you can do an iframe element potentialy but I have not messed with that as much)
B. The 'input' element is text based but you MUST match the id and name to the name of your parameter passing in.
C. The 'select' element gives a user 'option's of save methods to output directly to common types.
D. The 'input' for a type of 'submit' ensure the form will post to itself with the data prescribed.
<!DOCTYPE HTML>
<html>
<head>
<title>SSRS Tester</title>
</head>
<body>
<form id="SSRSRender" action="http:// (reportservername)/ReportServer?/(pathtoreport)" method="post" target="_self">
<H3>Enter some detail for the report to render</H3>
My Variable 'Test': <input type="text" id="Test" name="Test">
<br/>
My outputs:
<select ID="rs:format" name="rs:format" size=1>
<option value="HTML4.0">HTML 4</option>
<option value="IMAGE">Tiff Image</option>
<option value="PDF">PDF</option>
</select>
<br/>
<input type="submit" value="Render Report">
</form>
</body>
</html>
If you want to do more types of input variables to dynamically get SSRS to render as you want outside of the SSRS landing page you need to determine if you want to use:
The service with some front end with scripting like javascript with HTML
Something more easy to control will pre built tools like 'Report Viewer' with ASP.NET or a client application in C# or VB.NET
Create the service proxy yourself in a class library and do the calls in code directly as well as the formatting
Trying to create a rest URI programatically is better done by contacting the service and using built in methods IMHO rather than trying to make a string. It may be a little more of a learning curve but it will help you in the end.
<form action=post ...>
//...
<td><select name="data">
<option value="1" $isSelected_1>1</option>
//....100 options...
<option value="148" $isSelected_100>100</option>
</select>
</td>
//...
I'm generating html inside a C program. However, I need to check the options selected or unselected and I think its bad to create 100 variables(also many if statements...). What could be the best solution?
an array, and loop?
psuedo code:
a[1] = true;
...
a[n] = false;
for(i = 1 -> n)
<option value='i'+(a[i] ? selected : '')>...
From your question, it's a little difficult to know what you are trying to do. If you are just needing to store 100 options and check which ones are selected, you could store the results in an array and then loop over them using for and take appropriate action.
With that said, I wouldn't use C for this unless I had no other option. If you have the option, you should really use a language with has better string support and which manages memory for you. A good example would be something like Perl, Python, or anything but C.
Use `arrays, loops or even structures
struct variables{
//your variables
}
or
int variables[100]={/*your variable stuffs*/}
that should work!
and you could probably use Javascript for that.
I'm working on get my site validated in an attempt to iron out issues with it showing up incorrectly on IE, and I'm getting an error: document type does not allow element "script" here. It's from me placing the <script> tag within the <select> tag on the javascript drop down menu form I have.
Is there any way to get this validated? Or any work arounds?
The site in question is Blue Devil Books
And the specific code snippit is:
<noscript>This site requires that Javascript is enabled on your browser!</noscript>
<select name="CLASS"><script type="text/javascript">dynlist.printOptions("CLASS")</script>
</select>
<select name="SEC"><script type="text/javascript">dynlist.printOptions("SEC")</script>
</select>
<input type="submit" value="Search" />
</form></div></div>
Put your script outside the selects completely and then use innerHTML to modify their content. The following example assumes two things:
1) The name of the select element is always the same as the variable passed to printOptions e.g. if the name is "CLASS" then the contents should be printOptions("CLASS")
2) printOptions should be replaced with options which is an identical method except that instead of printing the options, it should instead return them.
<noscript>This site requires that Javascript is enabled on your browser!</noscript>
<select name="CLASS"></select>
<select name="SEC"></select>
<input type="submit" value="Search" />
</form></div></div>
<script type="text/javascript">
var selects = document.getElementsByTagName("select")
for (i = 0; i < selects.length; i++) {
var name = selects[i].getAttribute("name");
var options = dynlist.options(name);
selects[i].innerHTML = options;
}
</script>
Select elements can contain only <option> elements. There is no way to make it valid without writing according to the spec.
You could write out the entire select element with JS but, frankly, I'd move the logic server side and remove the dependency on JS entirely.