dear all..i want my input form automatically make all character become big size..
and also without press a capslock button...i want all data which have been input into DB in capital format..what's code to make it?
One simple way in jQuery is to convert the the value to uppercase after every keyup event:
$(document).ready(function(){
$('#myfield').keyup(function() {
var t = $(this);
t.val(t.val().toUpperCase());
});
});
Remember that this only changes the value in the UI on the client. When the user submits the form, it will send this uppercased value, but a malicious user could send data that was not uppercased, so you probably want to use an upcase method on your server, either in your CGI code (PHP, Perl, Java or whatever you're using), or in your SQL insert statement.
As Matthew said, strtoupper() will work.
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper($str);
echo $str; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
Using Javascript to filter something that is going into a database, is bad. What if the user decides to turn of Javascript? You can do it, but it will have to be done again when in the backend code, so it's a waste of time for something like this :)
You can use the PHP function strtoupper.
Related
I have input in html like this.
<input name="hoteltaxi" type="text" style="text-transform: uppercase;">
These inputs send the information throughout a post method. The PHP file that receive the information, got to save it in a mysql database.
To this point, is ok. Everything is working, but i have a little question about the form style.
If css can transform the value presentation... can also transform the value that i send to php? ¿Or is just presentation? Because, i really need to see this in uppercase, but i need to store with PHP in the original string format (can also be numbers, lowercases, and uppercases, doesn't matter) because from the original string, previously stored, will use it to make a MD5 hash.
The code is my frenemy.
The answer is No
You can see it clearly in this screenshot
If you really want the data to be transformed to uppercase do it on server side like this
$hoteltaxi = strtoupper($_POST['hoteltaxi']);
more about strtoupper
Or if you want it to be done on client-side a little bit of javascript can help you
$('input[name="hoteltaxi"]').change(function(){
var self = $(this);
self.val(self.val().toUpperCase())
})
I'm making a website where im alowing my users (after that they are loged in) to Add a (car) advertisement!
I have a form where the user can submit his car information.(add-vehicle.php)
Now I want to display each new advertisement in my list-view. (car-list.php)
How can I do this?
Use urlencode /urldecode to pass variables in url's urlencode
I recommand to use urlencode('string')
and then later when get your variable with urldecode('string')
Response to your comment:
if (isset($_GET['merk'],$_GET['car_id'],$_GET['titel']) === true )
{
$merk = urldecode(trim ($_GET['merk']));
$car_id = urldecode(trim($_GET['car_id']));
$titel = urldecode(trim($_GET['titel']));
}
You're changing a space into a hyphen. If it is stored in the database as a space, it will never find it because "This Entry" is different from "This-Entry". As others said, urlencode will work better, but if you still want to replace the space with a hyphen, just make sure that it is done the same in the database as well.
First, nobody in this world will know what you have in your database to tell what's the problem! At least post an example data.
Second, you must be sure of what you have and what you are comparing to.
You are basically asking if a is equal to b and to be fair that's something that you should be able to tell if you're programming!
Third, you should implement a methodology that allows you to quickly test your code, and that's from printing your data to the browser to a fully automated test.
I'm building a very AJAX site which means posting a lot of information to the server, sometimes typed by a user.
this is how I'm posting things
xmlhttp.open("POST", 'somepage.php' ,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send('post=stuuf I want to send');
An example of my problem is this, someone types FOO BAR as their name which would post firstName=FOO&lastName=BAR
which in php gets you $_POST['firstName'] is FOO and $_POST['lastName'] is BAR
but if someone types the name FOO&BAR SMITH it would post like this firstName=FOO&BAR&lastName=SMITH
which in php gets you $_POST['firstName'] is FOO and $_POST['BAR'] which has no value and this start to fall apart. It means I have to replace & in everything that is posted and I'm finding it annoying.
Is there a way to tell php to ignore any &, and just send one big string. when I need to send multiple values I was planning to break them up with an '_' I could then replace any user typed _ with _ and never have to worry about it again.
Could this be done in .htaccess or if not then in the php file itself?
Thanks for any help
Don't do this on the PHP end... send a proper HTTP request! You are mangling all of your data client-side. If you're sending URL encoded data, send it URL encoded.
No, but you absolutely must escape your data before using it as a string inside the ajax request.
You should encode the data you want to sent using encodeURI or encodeURIComponent. That way you can send whatever characters you want.
The following script has been created to test if the value of a db field has changed and if so then reload the page and if not, alert the user that the change has not happened.
The alert is just to see what is being returned by the .post function.
The auto_refresh works fine as i need it to check every 5 seconds, when the if() condition is set to '==' the page alert shows and if it is set to '!=' the page continually reloads.
jQuery.post is getting the db field data but it doesn't seem to be able to compare the 2 values correctly.
any help would be greatly appreciated, thanks
var auto_refresh = setInterval(function(){
$.post("/index.php/listen", function(data) {
if($('#slide').html() != data)
{
window.location.reload()
}
else
{
alert('its the same'+ data);
}
});
}, 5000);
EDITED
Rather than trying to parse raw data, why not pass HTML from the $.post() like:
<p>4</p>
Then the jQuery inserts the the replaces the p tag with the new version from the $.post()
because the html is passed on there is no white space and the comparison can be made correctly.
I don't think it is very safe to compare the new value with an html. Some browsers might add spaces or unwanted chars. I'd try to save the old value in an input of type hidden and use the .val() or, event better, in a variable. It depends of your scenario.
If $('#slide').html() == data
then that means that the conditional failed, it was not equal, so it showed the alert.
The problem is that the data variable might come back with a few extra white spaces. If I were you, I'd try to parse a small section of the data variable, and a small section of the html in slider and compare those values.
Like if slider has something within a p tag or an input value, compare it to the data to see if it has that same value returned in that p tag or input value, then replace all the whitespaces with an empty string just to be safe.
Btw, try not to use alerts since you can't really know for sure if there is an extra whitespace. Try to use something like "debugger" if using IE with visual studios, or console.log when using chrome or firefox.
You are comparing two html strings: one is serialized from the DOM, and another is from a server response.
There's no guarantee that the two strings will ever be the same! Think about it: the same rendered html can have many string differences. E.g. click and click are both the same HTML, but different strings.
You can take two different approaches here:
You can create some kind of canonicalization routine that guarantees that two html fragments you consider "the same" will have the same string form. Run both html fragments through this routine, then compare.
You can manage versions more explicitly.
Include some kind of version indicator:
You can use the ETAG header (which means you can take advantage of http caching mechanisms).
You can include some kind of version number in the html itself (maybe in a data-version attribute), and compare those.
You can keep the html string from your server separately and compare against that.
hey, I trying to enter the text in lowercase letter but when it comes to textbox it must be in uppercase if anyone can do this.
You can do this with CSS, no need for JavaScript or PHP
text-transform:uppercase
text-transform:lowercase
Add these to the style of each element class.
Or if you are resorting to inline styling, do this.
<input type="text" style="text-transform:uppercase;" />
String to uppercase with PHP (php.net doc):
strtoupper("Hello")
Output: HELLO
String to uppercase with JavaScript (java2s.com):
var s = new String("Hello")
s.toUpperCase()
Output: HELLO
Your options are:
As Raoul said, use CSS. If you possibly can, this is your best bet.
Let the user type in lower case, then transform it when they leave the field (blur, etc.) or when you save/process the text (e.g., on the server, whatever). Here's a blur example:
document.getElementById('theIDOfTheTextArea').onblur = function() {
this.value = this.value.toUpperCase();
};
Live example
Do it with JavaScript in the keydown or keypress event. Despite the various attempts intermittently posted here, doing this with JavaScript not trivial. It's trivial to identify the keypresses you want to handle and to cancel the event to prevent that keypress being added; but then inserting the character you do want is non-trivial. (Sadly, the keyboard events don't just let you substitute a different character; that would be nice, but they don't.) It unfortunately requires that you use text ranges / selections and gets you into areas that vary cross-browser. You'd probably need to leverage a library like Rangy to do it. I'd Just Say No and go the CSS / post-processing route.
The answer to this post will solve your problem.
Get the textbox element by id
Set an onBlur listener and convert its value using string.toUpperCase()
Have you check this
Upper
$("#idoftextbox").blur(function(){$(this).val($(this).val().toUpperCase())});
Put this in an onload event
Easy:
textareaElement.onkeydown = function(e) {
//make sure IE gets it
e = e || event;
//don't insert
e.preventDefault();
//catch the ASCII key code, and convert it to uppercase letter
this.value += String.fromCharCode(e.keyCode).toUpperCase();
}