Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
please guys am trying to create a form that contain 3 drop down menus but am having problems sending the values from the drop down list to my database. this is what the script looks like..
JavaScript
<select name="mySelect" id="mySelect" onchange="getSelectedValue();">   
    <option value="1">Text 1</option>   
    <option value="2">Text 2</option>   
</select>   
  
<script type="text/javascript">   
function getSelectedValue() {   
    var index = document.getElementById('mySelect').selectedIndex;   
    alert("value="+document.getElementById('mySelect').value);   
    alert("text="+document.getElementById('mySelect').options[index].text);   
}   
</script> 
and this is the php..
PHP
$interest = $_GET["i"];
      $webaddr = $_GET["w"];
      $discovery = $_GET["d"];
      $budget = $_GET["b"];
      $requirements = $_GET["r"];
      $funame = $_GET["f"];
      $lname = $_GET["l"];
      $quotemail = $_GET["q"];
      $cname = $_GET["c"];
      $tel = $_GET["t"];

      $email = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

            $error_message = "Invalid Email Address.";

             if(!preg_match($email,$quotemail)) {

  echo"<div style='color:red;font-family:Calibri;margin:0px 0px 0px 0px;'>'$error_message'</div>";


}
          else
          { mysql_connect('localhost', 'root', 'n3v1g90');
          mysql_select_db('webmakaz');
          mysql_query("INSERT INTO QuoteRequest (interest, webaddr, discovery, requirements, fname, lname, email, cname, tel) VALUES ('$interest', '$webaddr', '$discovery', '$budget', '$requirements', '$funame', '$lname', '$quotemail', '$cname', '$tel')");
          echo"<div style='color:#444;font-family:Calibri;margin:22px 0px 0px 0px;'><span>Quote received, We would get back to you shortly!</span>"; }
          ?>




i dont know what else to do..
Posted
Updated 6-Jul-14 7:26am
v2
Comments
Sergey Alexandrovich Kryukov 6-Jul-14 13:26pm    
And what is that problem?
—SA

You have more items in your values list than in the columns list in your SQL query - I think you need to add the 'Budget' column name.
 
Share this answer
 
i have ...i think the problem is with the javascript code. now the values are sent to the database but shows object HTML SelectElement instead of the actual value of the drop down options.

i think what i need is the correct javascript function to retrieve the selected value of the drop down list
 
Share this answer
 
Ok, Try this, According to your question, add the id="mySelect" to each of the option values of the select options, so that the javascript gets the id for each of the options selected by the user.
Remove this function "
onchange="getSelectedValue();
" and use this put this as ur form action
C#
function getSelectedValue() {

var mySelect= encodeURI(document.getElementById('mySelect').value);



.
Hope this is not confusing.
It has to work
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900