/    Sign up×
Community /Pin to ProfileBookmark

How to get auto response value by using Two Drop-Down List in PHP & Ajax?

<html>
<head>
<title> Upgrade Cost</title>
<script src=”//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js”></script>
</head>
<form method=’POST’ action=’home.php’>
Name : <input type=”text” name=”name”/><br/><br/>
Email Id : <input type=”text” name=”email_id”/><br/><br/>
Contact Number : <input type=”text” name=”contact_number”/><br/><br/>
I have :
<select id=”old”>
<option value = “select_option”>Select Option</option>
<option value = “one”>One</option>
<option value = “two”>Two</option>
<option value = “three”>Three</option>
<option value = “four”>Four</option>
<option value = “five”>Five</option>
</select><br/><br/>
I want :
<select id=”new”>
<option value = “select_option”>Select Option</option>
<option value = “one”>One</option>
<option value = “two”>Two</option>
<option value = “three”>Three</option>
<option value = “four”>Four</option>
<option value = “five”>Five</option>
</select>
</form>
<!– <button id=”btn_check_value”>Check for value</button> –>
<script>
$(document).ready(function(){
$(‘#new’).on(‘change’,function(){
var old_val = $(“#old option:selected”).val();
var new_val = $(“#new option:selected”).val();
$.ajax({
method: “POST”,
url: “home.php”,
data: { old: old_val, new: new_val }
})
.done(function( msg ) {
document.write( msg );

});
})
})
</script>
</html>
<?php
if(isset($_POST[‘old’]) && isset($_POST[‘new’])){
$old = $_POST[‘old’];
$new = $_
POST[‘new’];
if($old==’one’&&$new==’two’){

// echo json_encode(array(‘Cost 10$’));
echo “Upgrade Code : 10$”;
}

elseif($old==’one’&&$new==’three’)
{
echo “Upgrade Code : 20$”;
}
elseif($old==’one’&&$new==’four’)
{
echo “Upgrade Code : 30$”;
}
elseif($old==’one’&&$new==’five’)
{
echo “Upgrade Code : 40$”;
}
else{
echo “Choose Valid Options”;;
}

}
?>

I have a couple of doubts, first one how to retain the dropdown value after ajax worked, now after ajax run the drop down value refresh like Selection Option, i need the option should be retained the second one why i am getting this error
[upl-image-preview url=https://www.webdeveloper.com/assets/files/2019-04-08/1554715899-307237-aaa.png]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@VITSUSAApr 08.2019 — This Video will be more helpful to you -

https://www.youtube.com/watch?v=HRV2zEIMBqU
Copy linkTweet thisAlerts:
@Aveeva7authorApr 10.2019 — Thank You, How to save my AJAX value into the database.

i have customer input form, all the fields requested by the customer, along with drop down value, everything okay, but the ajax value only the issue, how to save my ajax value into database table specified column,now all the fields filled expect price how to handle Ajax.

my code : upgradecost.php -> https://paste.ofcode.org/eNcz9v2yFTNZ4QFKa4qtti & ajax_data.php -> https://paste.ofcode.org/u6zjDKDXu7a9EaWdgpcuzT

and my output -> https://snag.gy/vJtH7C.jpg ajax_data.php -> https://snag.gy/LSGnp8.jpg
×

Success!

Help @Aveeva7 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...