I have this syntax:
<input onkeypress="return event.charCode >= 48 && event.charCode <= 57">
I use it on inputs to allow only numbers.
But now i need to allow the enter key too since i can no longer use a button to submit the form(personal reasons).By now i found this:
event.charCode = 13 // allows enter key
but i can't seem to find how to build the onkeypress syntax.Any help ? Thank you.
you can try:
onkeypress="return event.charCode >= 8 && event.charCode <= 57"
In this way you can allow enter key,numbers..and few other characters,except for alphabetic characters.I don't see any other way.
Source: click
You might try:
onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 13"
event.charCode >= 48 && event.charCode <= 57 is for numbers 0-9
event.charCode == 13 is for enter
If you do something like:
onkeypress="return event.charCode >= 8 && event.charCode <= 57"
and you want the user to be able to delete or backspace make sure you include:
onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.keyCode == 8 || event.keyCode == 46'
The keycodes to 8 and 46 are the delete and backspace. The first solution only works completely in chrome.
It's not a very good style to include js code into html. Also if there is more than one input you need to avoid code duplicating.
So include this to your js file, the other code can be the same
$('.div-with-multiple-inputs').find('input').on('keypress', function() {
return event.charCode >= 48 && event.charCode <= 57;
})
This works for me, allow only numbers 0-9 and .
onkeypress="return event.charCode >= 46 && event.charCode <= 57"
Related
I'm having issues with the Perl range operator when assigning a range to my variable.
I have an HTML table that outputs numbers from a SQL query. How can I add a range from 98-99 to color code the data yellow?
I have this working for other cases (<100 and >100) but can't seem to get the 3rd option to work.
Thank you in advance for helping!!!
my $highlightProjMoves3300red = ($variableProjMoves3300 < 100) ? ' STYLE="COLOR:RED"' : '';
my $highlightProjMoves3300green = ($variableProjMoves3300 > 100) ? ' STYLE="COLOR:GREEN"' : '';
my $highlightProjMoves3300yellow = ($variableProjMoves3300 = (98..99)) ? ' STYLE="COLOR:YELLOW"' : '';
<tr>
<td>GATE</td>
<td>3300</td>
<td>$variable3300</td>
<td>$variableYTRG3300</td>
<td $highlight3300>$variableYESTDELTA3300</td>
<td>$variableDTDMOVES3300</td>
<td $highlightProjMoves3300red $highlightProjMoves3300green $highlightProjMoves3300yellow >$variableProjMoves3300%</td>
<td>$variablePASTWEEKMOVES3300</td>
<td></td>
<td></td>
<td></td>
<td>$variableCURRENT_WIP_GATE</td>
</tr>
Your approach is failing because the range operator generates a list of values. Comparing a variable to a list doesn't give you a true result if the list contains the value.
You'd need to search for it.
#!/usr/bin/perl
use v5.20;
use warnings;
use List::MoreUtils qw(any);
my #values = (50, 98, 200);
foreach my $variableProjMoves3300 (#values) {
if (any {$_ == $variableProjMoves3300} (98..99)) {
say "$variableProjMoves3300 is between 98 and 99 (inclusive)";
}
}
This isn't an approach I'd recommend though, at least not for dealing with the case "between two numbers".
A traditional
if (98 <= $variableProjMoves3300 && $variableProjMoves3300 <= 99) {
… is clearer and (I expect) faster.
98 <= $variableProjMoves3300 <= 99 # 5.32+
or
98 <= $variableProjMoves3300 && $variableProjMoves3300 <= 99
That said, having a collection of variables make no sense. You want to set the style based on the number of moves, so you need one variable for the style.
my $highlightProjMoves3300Style =
$variableProjMoves3300 < 98 ? ' STYLE="COLOR:RED"'
: $variableProjMoves3300 < 100 ? ' STYLE="COLOR:YELLOW"'
: $variableProjMoves3300 == 100 ? ''
: ' STYLE="COLOR:GREEN"';
Or if you didn't mean to skip 100,
my $highlightProjMoves3300Style =
$variableProjMoves3300 < 98 ? ' STYLE="COLOR:RED"'
: $variableProjMoves3300 < 100 ? ' STYLE="COLOR:YELLOW"'
: ' STYLE="COLOR:GREEN"';
Right now I am working with Spark/Scala and I am trying to join multiple dataframes to get the expected output.
The data input are CSV files with call record information. These are the input main fields.
a_number:String = is the origin call number.
area_code_a:String = is the a_number area code.
prefix_a:String = is the a_number prefix.
b_number:String = is the destination call number.
area_code_b:String = is the b_number area code.
prefix_b:String = is the b_number prefix.
cause_value:String = is the call final status.
val dfint = ((cdrs_nac.join(grupos_nac).where(col("causevalue") === col("id")))
.join(centrales_nac, col("dpc") === col("pointcode_decimal"), "left")
.join(series_nac_a).where(col("area_code_a") === col("codigo_area") &&
col("prefix_a") === col("prefijo") &&
col("series_a") >= col("serie_inicial") &&
col("series_a") <= col("serie_final"))
.join(series_nac_b, (
((col("codigo_area_b") === col("area_code_b")) && col("len_b_number") == "8") ||
((col("codigo_area_b") === col("area_code_b")) && col("len_b_number") == "10") ||
((col("codigo_area_b") === col("codigo_area_cent")) && col("len_b_number") == "7")) &&
col("prefix_b") === col("prefijo_b") &&
col("series_b") >= col("serie_inicial_b") &&
col("series_b") <= col("serie_final_b"), "left")
This generates a multiple output files with the call data records processed, including the column "len_b_number" which means the length of the b_number field.
I was doing some tests I already find that for some reason the expression "col("len_b_number")" is returning the column name "len_b_number" instead the length values which are 7, 8 or 10. This means that the col("len_b_number") == 7 OR col("len_b_number") == 8 OR col("len_b_number") == 10 conditions will never work because the code will always compare with the column name.
At this moment the output is blank because the col("len_b_number") doesnt match with 7, 8 or 10. I will like to know if ypou can help to understand how to extract the value from this column.
Thanks
Try using === instead of ==.
I could not get your error.
&& col("len_b_number") == "8"
should be:
&& col("len_b_number") === "8"
i need help about my code.
i cant figure out what im doing wrong.
here is the criterias i try to code (http://imgur.com/a/iU3bl)
and data file ( https://drive.google.com/file/d/0ByYia_19kCK4SXJMT2Q2ZHJHLVU/view?usp=sharing )
so i code this for solve it. but code always say 'NS' and i want "regime" data respect my table.
thx for all who try to help
data = xlsread('Data.xls');
PP=data(:,2);
TP=data(:,4);
BP=data(:,6);
region={ };
for i=1:length(data)
if PP(i)>=52 && 35>=TP(i);
region{i}='NF';
elseif 40<=PP(i) & PP(i)<52 & (TP(i)<=20);
region{i}='NS';
elseif (40>PP(i)) && (BP(i)>=45) && TP(i)<=20;
region{i}='SS';
elseif (PP(i)<=20) && (45<=BP(i)) && (TP(i)<=40);
region{i}='SS';
elseif (PP(i)<=20) && (40<=TP(i) && TP(i)<=52) ;
region{i}='TS';
elseif (PP(i) <=32) && (TP(i)>=52);
region{i}='NF';
else
region{i}='UN';
end
end
Your P_plunge is only between 40 & 52. It makes perfect sense that they all fall under NS.
Perhaps you might want to use column 1 for the data?
Also use && instead of &.
Good luck!
can anyone help me in this issue.
I want to avoid special characters(!##$%^&*()) in text field.
Actually I have added javascript code for this.
now I cant enter the spl characters. it's working perfect.
But the problem is, the data is not going to be inserted after submitted.
<script language="Javascript" type="text/javascript">
function alpha(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
</script>
'customCode' => '<input type="text" onkeypress="return alpha(event)">',
You have missed the name of textfield in customCode. Your customCode should be like:
'customCode' => '< input type="text" onkeypress="return alpha(event)" name="your-textbox-name">',
I had a programmer write a Perl script for my site.
One of the functions is to update price/stock when a certain condition is met.
# update when price/stock conditions met
if ( ($force_price_updates == 1) ||
($data->{'price'} <= $product_price && $data->{'quantity'} > 0) ||
($product_quantity == 0 && $data->{'quantity'} > 0) ) {
What the above is not doing is not updating the price if the new price is higher. It updates the stock value, but if the new stock comes at a higher price, I lose out. Stock gets updated and but the price is not.
The script goes through a number of feeds and if the same product is found in any of the feeds, the script should amend price/stock change according to the rule above.
I can't find the programmer and my Perl knowledge is limited. I understand what the code is doing, but don't know what it should do if the price is higher and stock is greater than zero.
You can add the extra condition you're looking for to that statement.
The condition you're looking to match is:
$data->{'price'} > $product_price && $product_quantity > 0
So the final version would look like this:
if (($force_price_updates == 1) || ($data->{'price'} <= $product_price && $data->{'quantity'} > 0) || ($product_quantity == 0 && $data->{'quantity'} > 0) || ($data->{'price'} > $product_price && $product_quantity > 0)) {