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

Feb 21st, 2014
DreamIt
Category:
Programming
Price: $20 USD

Question description

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('');
 });
}

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Boston College
PREMIUM TUTOR

Studypool has helped 1,244,100 students

5 Reviews


Summary
Quality
Communication
On Time
Value
ashleyisgod
Nov 24th, 2016
" Top quality work from this guy! I'll be back! "
Molly_Moon
Nov 2nd, 2016
" AMAZING as always! "
Hemapathy
Oct 10th, 2016
" all I can say is wow very fast work, great work thanks "
BlueOcean
Sep 27th, 2016
" Awesome! Exactly what I wanted. "
kevin12622
Sep 18th, 2016
" Goes above and beyond expectations ! "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1826 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors