?
Solved

Creating a text string from 3 drop down boxes (hopefully pretty easy)

Posted on 2012-03-16
5
Medium Priority
?
233 Views
Last Modified: 2012-03-19
Hi All,

Im pretty new to creating webpages so please be gentle :)

I need a piece of code, php or even a name of an element to create a string from 3 drop down boxes, box1, box2 and box3

Heres an example

Box1 - ford = for, volkswagen = vol, porsche = por
Box2 - red = red, yellow = yel, blue = blu
Box3 - long = lon, medium = med, short = sho

Hence, selecting Volkswagen in box1, yellow in box2 and medium in box3 would produce the string (possibly in a box below the dropdowns) volyelmed (i.e. like a trucated product code)

Hope this makes sense, any help much appreciated.
0
Comment
Question by:johnsit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ScottNL1
ID: 37729553
You are submitting a form?

is so, the easy way is:

$string = $_POST['box1']." ".$_POST['box2']." ".$_POST['box3'];

echo $string;
0
 

Author Comment

by:johnsit
ID: 37729602
Thanks for the reply,

No, I am not, I simply want to display the string underneath the drop downs on the same page.
Basically it is to give a user a product code by selecting from a drop down.
0
 
LVL 1

Accepted Solution

by:
ScottNL1 earned 2000 total points
ID: 37730178
try this

<script>


function product_code(){
  var box1 = document.getElementById("box1");
  var box2 = document.getElementById("box2");
  var box3 = document.getElementById("box3");
  document.getElementById("code").innerHTML = box1.options[box1.selectedIndex].value + box2.options[box2.selectedIndex].value + box3.options[box3.selectedIndex].value;

  ;

}


</script>


Car:
<select id="box1" onchange="product_code();">
       <option value="for">ford</option>
       <option value="vol">volkswagen</option>
       <option value="por">porsche</option>
</select>
<br />
Color:
<select id="box2" onchange="product_code();">
       <option value="red">red</option>
       <option value="yel">yellow</option>
       <option value="blu">blue</option>
</select>
<br />
Type:
<select id="box3" onchange="product_code();">
       <option value="lon">long</option>
       <option value="med">medium</option>
       <option value="sho">short</option>
</select>
<br /><br />

<div id="code" style="color:red;font-size:1.2em"></div>

Open in new window

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 37730189
Post a link to the page, or the HTML and we should be able to give you some code.


Cd&
0
 

Author Comment

by:johnsit
ID: 37736697
Thanks very much scottNL1, exactly what I was after!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question