Solved

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

Posted on 2012-03-16
5
230 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
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code Manager | Snippits 2 35
reverse engineer .sql from php files 11 33
HTML <font style="color:red"> 9 29
send email part1 9 22
Find out what you should include to make the best professional email signature for your organization.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

791 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