Menu
Hi this is how my ticket booking form looks like:
a drop down menu stating day(Mon, Tues, Wed etc)
then based on day selected, on the same page itself, it will display all the movies screening on the selected day inside textarea?
how do I do that with javascript?
can someone who helped me with the coding, try add some explanations on the codes used so i can learn from it too.
switch(index){ //base on selected index change the movie title accordingly
case 0: movie="Monday Movie";break;
case 1: movie="Tuesday Movie";break;
default: movie="other day";break;
}
//fill the textarea with the corresponding movie titles based on selection
eleTxtArea.innerText = movie;
}
</script>
</head>
<body>
<Select id="ddlDays" onchange="showMeTheMovies()">
<Option>Monday</option>
<Option>Tuesday</option>
<Option>Wednesday</option>
<Option>Thursday</option>
<Option>Friday</option>
<Option>Saturday</option>
<Option>Sunday</option>
</select>
<Textarea id="txtMovies"></textarea>
</body>
[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var movies=new Array();
movies[0]=new Array('Sunday movie 1','Sunday movie 2','Sunday movie 3','Sunday movie 4','Sunday movie 5','Sunday movie 6');
movies[1]=new Array('Monday movie 1','Monday movie 2','Monday movie 3','Monday movie 4','Monday movie 5','Monday movie 6');
movies[2]=new Array('Tuesday movie 1','Tuesday movie 2','Tuesday movie 3','Tuesday movie 4','Tuesday movie 5','Tuesday movie 6');
movies[3]=new Array('Wednesday movie 1','Wednesday movie 2','Wednesday movie 3','Wednesday movie 4','Wednesday movie 5','Wednesday movie 6');
movies[4]=new Array('Thursday movie 1','Thursday movie 2','Thursday movie 3','Thursday movie 4','Thursday movie 5','Thursday movie 6');
movies[5]=new Array('Friday movie 1','Friday movie 2','Friday movie 3','Friday movie 4','Friday movie 5','Friday movie 6');
movies[6]=new Array('Saturday movie 1','Saturday movie 2','Saturday movie 3','Saturday movie 4','Saturday movie 5','Saturday movie 6');
function showMovies(val,who){
if(val==0)who.value='No day selected.';
else{
who.value=movies[val-1].join('n');
}
}
//-->
</script>
</head>
<body>
<form>
<select name="days" onchange="showMovies(this.selectedIndex,this.form.display)">
<option>select a day</option>
<option>Sunday</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
</select>
<textarea cols=50 rows=10 name="display"></textarea>
</form>
</body>
</html>[/code]
Cheers - Pit<i>
</i>//Using Array() constructor declaration
var myArray=new Array(x, y, z);
<i>
</i>//Using array literal declaration
var myArray=[x, y, z];
<i>
</i>var myArray=new Array();
myArray['userName']='HaganeNoKokoro';
myArray['favoriteAnimal']='cat';
myArray['favoriteDrink']='coca-cola';
<tr>
<td class="body"><div align="right">Select Model Color</div></td>
<td><select name="modelColor" onchange="showImage()">
<option value="c0" selected>--Select Model--</option>
<option value="c1">Blue</option>
<option value="c2">Green</option>
<option value="c3">Yellow</option>
<option value="c4">Orange</option>
<option value="c5">Red</option>
</select> </td>
</tr>
<tr>
<td class="body"><div align="right">Picture</div></td>
<td>//display image according to model and color selected</td>
</tr>
<tr>
<td class="body"><div align="right">Enter Quantity</div></td>
<td><input name="quantity"></td>
</tr>
<tr>
<td class="body"><div align="right">Total</div></td>
<td><input name="total" >//display total here</td>
</tr>
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Page</title>
<script language="JavaScript">
var productDetails = new Array(4);
function letsGo(){
var selectedColor = document.getElementById("productColor");//get color
var selectedProduct = document.getElementById("product");//get product
var productDesc = document.getElementById("productDesc");//get textarea element to hold the desc
var ele;
ele=document.getElementById("pic");
if (selectedProduct.value != "p0"){
displayDesc="other day";
productDesc.value = displayDesc;
productDetails[0] = "p1";
productDetails[1] = 50; //hard code in the price
}
if(selectedColor.value !="c0"){
//note change to .innerHTML and edit the src according to where image is held
pic.innerText = "<img src='" + selectedColor.value + ".jpg'></img>";
}
}
function validateAndCalulate(txt){
if(/D/.test(txt.value)){
alert('please input a number');
txt.value='';
}else{
if(txt.form.product.value !="p0"){
txt.form.total.value = txt.value * productDetails[1];
}else{
txt.form.total.value = "Please select a product";
txt.value = '';
}
}
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td class="body"><div align="right">Select The Model</div></td>
<td>
<select id="product" name="product" onchange="letsGo()">
<option value="p0" selected>--Select Model--</option>
<option value="p1">Product One</option>
<option value="p2">Product Two</option>
</select>
</td>
<td><textArea id="productDesc"></textarea></td>
</tr>
<tr>
<td class="body"><div align="right">Select Model Color</div></td>
<td><select name="modelColor" onchange="letsGo()" id="productColor">
<option value="c0" selected>--Select Model--</option>
<option value="c1">Blue</option>
<option value="c2">Green</option>
<option value="c3">Yellow</option>
<option value="c4">Orange</option>
<option value="c5">Red</option>
</select> </td>
</tr>
<tr>
<td class="body"><div align="right">Picture</div></td>
<td><span name="pic" id="pic"></span></td>
</tr>
<tr>
<td class="body"><div align="right">Enter Quantity</div></td>
<td><input type="text" name="quantity" onchange="validateAndCalulate(this)"></td>
</tr>
<tr>
<td class="body"><div align="right">Total</div></td>
<td><input name="total" id="total" value="Display total here" readonly></td>
</tr>
</table>
</form>
</body>
</html>
[/code]
if(selectedColor.value ="c1" && selectedProduct.value="p1"){
pic.innerText = "<img src='" + selectedColor.value + ".jpg'></img>";
}
selectedColor.value ="c1" && selectedProduct.value="p1"[/QUOTE]
[code=php]selectedColor.value=="c1" && selectedProduct.value=="p1"[/code]
the getPicture() does not work. The condition does not work[/QUOTE]
else
displayDesc="w5 product";
modelDesc.value = displayDesc;
shoppingCart[0] = "w5";
shoppingCart[1] = 150; //hard code in the price
[/QUOTE]
0.1.9 — BETA 5.18