www.webdeveloper.com
Results 1 to 4 of 4

Thread: JScript Drop Down Boxes with Calculations

  1. #1
    Join Date
    Mar 2013
    Location
    Australia
    Posts
    3

    JScript Drop Down Boxes with Calculations

    Hi, New at Javascript and have done a bit of playing around trying to figure out a answer but cant figure it out. Hopefully someone can help.

    have a Dropdown box (TYPE) that needs to populate a calculation in another form box (VALUE) and submit to database once submit is clicked.

    Code I have:

    Code:
    <p>NUMBER</p>
                <input name="contact_build" type="text" id="contact_build" value="<?php echo $row_contact['contact_build']; ?>" />
             
       
    <p>TYPE</p>
                <select id="contact_type" name="contact_type" />
    <?php $specresult = mysql_query("SELECT * FROM `types` ORDER BY type_value");
    while($specrow = mysql_fetch_array($specresult)){
    			echo '<option value="'.$specrow['type_name'].'">'.$specrow['type_name'].'</option>'; } ?>
    </select>
    
            
        
    
    <p>VALUE</p>
        <?php 
          $var1 = $row_contact['contact_build']; 
          $var2 = $row_value['type_value']; 
          $total = round ($var2 *  $var1); 
          echo "" . $total . ""; 
        ?>" />
    <input name="contact_value" value="<?php $var1 = $row_contact['contact_build']; $var2 = $row_value['type_value']; $total = round ($var2 *  $var1); echo "" . $total . ""; ?>" />
            
    
            <input type="submit" name="Submit2" value="Update" />

    So what I want to happen is: when user selects item from "TYPE" is changes the value in "VALUE" Box by the calculation to show the new figure before submit is clicked and without refreshing the page to save the new figures to the database. The second box cannot be changed by the user. I have played with JScripts and stuff but cant get it to work. I have only supplied the code Prior to J Script as I think I made a real mess of it.

    Also I know It is Mysql at present. I am just finalising learning PDO at the moment and AM GOING to be using PDO in the future. :-) But just want to get this sorted using the code I know at present, then I can change over to PDO.

    Please let me know if more info is needed.

    Thanks for your help :-)

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    give the target input an id of targ, then in your <select>, add onchange="targ.value=this.value"

  3. #3
    Join Date
    Mar 2013
    Location
    Australia
    Posts
    3

    It Worked - Sort Of... :-)

    Quote Originally Posted by rnd me View Post
    give the target input an id of targ, then in your <select>, add onchange="targ.value=this.value"
    Thanks heaps :-) Seems like a simple answer (for you experts) It seemed that I wasnt writing the command correctly and got it mixed up with each one. Now that part is working... I have got the transfer of info as needed... However the next part though is, if you see in the code its working out a formula where the "TARG" is. This is based from the number in the first box and then a number from another area. How would I make that "TARG" be the varable in the formula instead? So evertime the first box changes it changes the formula answer.

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    it's not clear to me how the actual HTML is seen in view-source.
    i try to avoid PHP, so i can't read what it's doing with specific fields or numbers or even how many box will even appear...

    i can make a formula to hit any input in the <select onchange>, so if you can post the generated HTML i can code up a handler in two seconds flat...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles