how to auto fill html input using different html input - php

<html>
<input name='name'>
<input name='handphone'>
</html>
I need some script to make if user type on name and their 'handphone' data that store on db will show on second input form
example if done
<form>
<input name='name' value='surya'>
<input name='handphone' value='081392111098'>
</form>

I think you need that if Any User type name input and if name is in database then headphone input autofill from database. For this You have to Use ajax or jQuery.
thanks

Related

HTML update input textarea everytime "Submit" it clicked

<html>
<script>
function changeText()
{
document.getElementById("input1").value = <?php echo '"'.$_POST['input'].'"'; ?>;
return true;
}
</script>
<form name="mainform" action="" method="post">
<input type="text" name="input" id="input1" />
<input type="submit" onclick = "changeText()" name="Submit" value="Submit!" />
</form>
<html>
i have this code here. can you make it work as intended ?
everytime i click Submit! i want to change the value of the textarea to the last input the user inserted.
PHP code is parsed by a PHP interpreter before any HTML output is sent to the browser.
If your form action is the same page and the same form will be shown before and after submission, then you can let PHP print the value of the input field directly into it.
<input type="text" name="input" id="input1" value="<?php echo htmlspecialchars($_POST['input']);" />
If you're trying to revert the value of this input field whenever a user clicks the submit button, then your code (even if it's prone to code injection) should work but this is useless since the page will be requested again when submit is clicked.
I assume you need to fill in
action=""
By the name of your file, like
action="myFile.php"
Few tips :
NEVER trust the user. The user can manually change the value of the input and send some dangerous values in your $_POST variable. You need to check it using filter_input() by example.
Like #Charles said this is pretty simple problem, use google next time.Here for example

stored the several value of the textbox into an array php

Im making my project, and my project is make a program that will enter name,age and address.
There was a 3 textbox and a submit button. when the user answer the 3 textbox and click submit button, the data or the input of the user will save into an array, but when the user try to input again the previous input will not be replace or it will be there together with the user new inputs, and later those input where use to save into mysql db, do you think this project is possible using php array? i have no sample code because i dont know how to start.thank you so much.
index.php
<form action='index.php' method='get'>
<input type='text' name='name[]'>
<input type='text' name='age[]'>
<input type='address' name='address[]'>
<input type='submit' value='Save'>
</form>
Simple solution is to use 'sticking form' - form elements that stick (keep) the values previously entered.
You can make a textbox sticky like this:
<input type='text' name='name' value='<?php isset($_POST['name'])? $_POST[\'name\']: ""; ?>' />
You need to sanitize the inputs, however, if you try to use it for some real application.

How can I dynamically change text based on input field?

How can I dynamically change a link based upon an input field in a form. For example, if I input 1.00 into the input field, I want to change the link to this:
donate.php?amount=1.00
Where the amount changes to the amount specified in the input field.
I'm guessing its JavaScript which isn't my strongest point but any help would be awesome. :)
Thanks
markup:
<input type="text" id="amount" onkeyup="changeLink(this);" />
donate now!
Javascript:
function changeLink(inputElement)
{
$('#donateLink').attr("href","donate.php?amount="+inputElement.value);
//console.log($('#donateLink').attr("href"));
}
jsfiddle working example here.
This can be done with html forms:
<form action="donate.php" method="GET" id="donateform">
<input type="text" name="amount" />
<input type="submit" value="Donate" />
</form>
You could also have input entered via a drop down list so they don't enter invalid values. Or you could validate the input with javascript. To use a link to submit the form, you can use javascript:
Donate
You don't need to do anything, just use a form. By using the GET method with a form and naming your input field 'amount', that will already be added to the URL at the time of form submission. Go ahead and try submitting a form when you enter 1.00 into the box. When the page loads, your URL will be donate.php?amount=1.00 like expected. The URL does not need to be changed whatsoever.
If you're using POST, I would merely suggest not doing this. It serves no purpose in that case.

How to Submit two values with only one submit button?

Hey im making a website were you can send other users emails.
My problem is when I go and submit it doesn't submit both values?
my Form has a text box where the user wants to send the email and another is a text area which is the message.
and i don't want 2 submit buttons
Have a look at http://www.w3.org/TR/html401/interact/forms.html#h-17.1 on how to create forms.
Your inputs need unique name attributes.
Example:
<form>
<input type="text" name="recipient_address" />
<textarea name="message_body"></textarea>
<!-- no real need for a name on the submit button -->
<input type="submit" value="Send Message" />
</form>
any value that you want to send to the server make sure it is in the form tag. When the user clicks your "submit" button all of the data in the form is sent off along with the page request. You can have as many items as you want in the form.
<html>
<head>
/*... your code here
...*/
</head>
<body>
<form name='sampleForm' action='sample.htm' onsubmit='ValidatethisForm()' method="post" enctype="multipart/form-data">
<input type='text' name='formElem1'>
<textarea name='formElem2'></textarea>
<input type = 'submit' value='submit'>
</form>
</body>
</html>
In the validate function once u finish your validations use "return true" to proceed. You can submit multiple form elements as long as they have different name attributes and the are within your form tag.
By far the best I have found is here
Happy Coding
Check your input and add a unique name attribute.

How to display records below form on submission in php without the use of database?

How to make the use of hidden variables as array for consecutive submission of data so that they can be used to display the records list.
I have a form with 4 text fields and a file upload field.. as i submit he form it should get appended to the list which needs to be displayed below the form, such that these values are NOT stored in the DB..
So in this case how can i use the post array to collect the data and display in the list below?
You can use hidden input fields to pass the input data to the next page. Example:
<form method="POST">
Name: <input type="text" name="names[]" />
<input type="submit" value="Add" />
<?php
foreach ($_POST['names'] as $name)
{
echo '<input type="hidden" name="names[]" value="'.$name.'"/>';
}
?>
</form>
<?php
print_r($_POST['names']);
?>
However, this will not work for the uploaded files. You have to save these as you get them and pass the filename in the form.
An alternative to this is to use sessions. These allow you to save some user data between page hits.

Categories