0

Hello i'm working on some project and i have 6 dropdowns and every has it values

Example in first dropdown i have:

<input type="checkbox" id="dt1" name="dt1" value="1">20 kW<br> 
<input type="checkbox" id="dt2" name="dt2" value="2">40 kW <br> 
<input type="checkbox" id="dt3" name="dt3" value="3">60 kW <br> 

And in Other i have:

<input type="checkbox" id="stv1" name="stv1" value="6">500 L<br> 
<input type="checkbox" id="stv2" name="stv2" value="7">1000 L<br> 
<input type="checkbox" id="stv3" name="stv3" value="8">"2000 L<br> 

But now i have many questions first how can i make drop down with only one selection? second question is how can i give result when someone choose from drop down one value 1 and from drop down 2 value 8 how can i make value1+value8=link?

Till now i have used

if (containsOnly(values, ['1', '8'])) {
        alert('something');
    }

but now i dont need alert, i need link so if someone can help me or do something on JS Fiddle that would be great

my latest work on this topic was this http://jsfiddle.net/KyleMuir/bUdra/5/ but now its not just choice a b or c, it must be choice a drop down with 3 or 4 choices and without alert.. If someone could help me it would be great

2
  • 1
    Sidenote: Those are not dropdown <select>...</select> codes; what you have (posted) are checkboxes. Two different animals altogether. ;-) Commented Mar 12, 2014 at 15:10
  • Yeah i now notice.. i didnt copy the full code :D Commented Mar 13, 2014 at 7:16

1 Answer 1

1

with this code you can get both values in the same file or in an other file just edit it to what you need:

<?php
    if($_POST) {
    $dd1 = $_POST['dropdown1'];
    $dd2 = $_POST['dropdown2'];

header('Location: file.php?dd1='.$dd1.'&dd2='.$dd2);
exit();
}
?>

<form action="" method="post">
    <select name="dropdown1">
        <option value="20">20 kW</option> 
        <option value="40">40 kW</option> 
        <option value="60">60 kW</option>
    </select>

    <select name="dropdown2">
        <option value="500">500 L</option> 
        <option value="1000">1000 L</option> 
        <option value="2000">2000 L</option>
    </select>
    <input type="submit" value="Calculate">
</form>

file.php could then be something like:

<?php
$dd1 = strip_tags($_GET['dd1']);
$dd2 = strip_tags($_GET['dd2']);

echo $dd1; //should give you the value from dropdown1
echo $dd2; //should give yout the value from dropdown2
?>

<!-- the php variables can also be used in javascript -->
<!-- don't know for sure if this is the correct way to use php in javascript but atleast should be something like this -->
<script type="text/javascript">
var dropdown1 = <?php $dd1; ?>;
var dropdown2 = <?php $dd2; ?>;
</script>
Sign up to request clarification or add additional context in comments.

5 Comments

How is the calculate() function supposed to be called? It's not in the OP's jsfiddle. Your answer is not fully functional.
Thanks for noticing I tried something in javascript but at the end changed it to php and forgot to take that out. changed it now
This is something to begin with.. but, how can i call them to make some action? example if dd1 value="20" is selected and dd2 value "1000" is selected then go to... how can i do that? that is only thing that i need right now..
header('Location: file.php?dd1='.$dd1.'&dd2='.$dd2); this line points you to a file where you start to calculate by a $_GET like $dd1 = $_GET['dd1'] you get the falue from the url
I gave you solved for your anwser up but can you help me a litlle bit more? i didn't get your response.. can you give me example how can i submit if selected values 40 and value 500 to a mysite.com/test.php ? I hope you understand me.. before i used if (containsOnly(values, ['1', '8'])) { alert('mysite.com/test.php'); } But that was for checkboxes and didnt open link instead it was given alert.. i hope you understand..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.