Solved

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

Posted on 2012-03-16
5
232 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 500 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
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.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

729 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