• Home
  • Blog
  • Using val() in jquery to lookup data from a input box according to what’s is selected from

Using val() in jquery to lookup data from a input box according to what’s is selected from

0 comments

I am having a problem with this script .It adds the data to the html contact field below according to what is selected from the customer field. But when I save the data it saves what is in the contact field in the customer field also. How can I stop this from happening.

All the scripts below worked just fine until I added the first one below

This is the jquery script I am using

function updateValue()
{
  $('#contact').val($('#customer').val());
}
//update once the page has loaded too
$(document).ready(function () {
  updateValue();
});

Here is the two html fields that are being used

<select name="customer"id="customer" class="responsetext1" onchange="updateValue();" >

<input name="contact"  id="contact">

The falling script are how the drop down gets its data for the customer field


$( document ).ready(function()
{
$.ajax({  //create an ajax request to load_page.php
  type: "GET",
  url: "signing.php",
  dataType: "html",  //expect html to be returned
  success: function(response){   
  $(".responsesign").html(response);
  //alert(response);
  }
  });
});

<?php
include("connect.php");
$id = $_SESSION['profile']['id'];
echo "<option value=''>SELECT A SIGNING</option>";
foreach($db->query("SELECT * FROM signings WHERE pid = '$id' AND done = 0") as $row) {
 
  echo "<option value=" . $row['id'] . ">" .$row['ordern']. "  " .$row['lname'] . "</option>";
 }

This is the ajax script that sends the data to the php script to save the data from the form

// JavaScript Document
$("#sub").click( function(event) {
 //stop the click event from bubbling
  event.preventDefault();
 $.post( $("#myForm").attr("action"),
  $("#myForm :input").serializeArray(),
  function(info){ $("#result").html(info);
  return false; // at end  
  });
 clearInput();
});
 
$("#myForm").submit( function() {
  return false;
});
 
function clearInput() {
 $("#myForm :input").each( function() {
  $(this).val('');
 });
}

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}