Jump to content

Php/javascript Dynamic Drop Down


Sarah

Recommended Posts

Hi all-

 

I'm having some trouble with a dynamic drop down box on one of my PHP pages.

 

I've been searching the net for examples, but mostly I've been seeing ones that dynamically change another drop down box underneath it. (For example, choosing a make of car in box A, and having it automatically update box B with the available models.)

 

I need it to do something different, not difficult, but just can't figure it out.

-----------

 

The purpose of my page is to add a customer name & info to a mySQL database.

The user can either choose from an existing customer in the database or enter in a new one.

If the user chooses an existing customer, the PHP code will query the database, printing out all available customer names in a < SELECT > menu. Like thus (note: the code does not work properly):

 

 

><tr>
 <td class="heading" align=right>Choose previous: </td>
 <td>
      <form name="completeform" method="post" 
                action="sales.php?action=addproj&go=2">
      <select name="contact" class="data">
         <option value="">--Choose contact--

 <?php
 //select all previous contacts
 $query = "SELECT ContactID,Company_Name 
                 FROM ContactTable
                 ORDER BY 'Company_Name'";
      //run query
      rq($res,$query);
      while ($rows = mysql_fetch_array($res)){	
           $id = $rows['ContactID'];
           $compname1 = $rows['Company_Name'];
  ?>
  
         <option value="<?php echo $id;?>"><?php echo $compname1;?>
<?php
} ?>

</select><input type=submit name=submit value="Complete"></form>
  </td>
</tr>

 

 

When the user clicks on an option in the select menu and clicks the 'complete' button, it should then reload the same PHP page, request the ID number, and fill in all appropriate information fields with the data with the ID from the select menu.

 

This is not doing so. Notice I want the form to submit to 'sales.php?action=addproj&go=2'? Well, after the click of 'Complete', the form is actually submitting to 'sales.php?action=addproj&go=1&id=&flag=', which is the submit value of another form outside of this code! I guess you can't nest forms or something?? Mad!!!

 

Can anyone provide any input? I've even tried JavaScript, but I can't get it to reload the PHP page & send the ID variable.

 

If anyone wants to see the page, I will provide more code or send a link.

 

Thanks in advance!

Link to comment
Share on other sites

This is not doing so. Notice I want the form to submit to 'sales.php?action=addproj&go=2'? Well, after the click of 'Complete', the form is actually submitting to 'sales.php?action=addproj&go=1&id=&flag=', which is the submit value of another form outside of this code! I guess you can't nest forms or something??

 

Hm...you lost me at Hi...

 

for the problem above..make sure you have different submit names.

<input type=submit name=submit value="Complete"> change to

<input type="submit" name="submitwhatever" value="complete">

 

and if you of course if u want to manipulate any of those post variable...

Check to see if form was submitted like so,

if (isset($_POST['submitwhatever'])) or something similar.

 

If that doesn't help...sorry

Link to comment
Share on other sites

I tried different submit names just now. Didn't work..... I'm still getting the same response.

Link to comment
Share on other sites

Yeah, I've tried different form names and now different submit names.

 

Do you know of a way to bypass the form submitting with just using

JavaScript? Like if I put an onClick button or the onChange handler in the 'select' tag that will reload the page? I tried it once but I kept getting errors.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...