Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2004, 07:08 PM   PM User | #1
ClueLess
Regular Coder

 
Join Date: Nov 2002
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
ClueLess is an unknown quantity at this point
displays message depend on the item that we've selected?

We have a simple contact form. What we would like is: when the users select item from the dropdown list, we would like a diff. message displays/shows (depend on the item that they've selected). How can we do that?

For example: if user selected Math – a message displays “Math: provide the problem." If user selected Physic – message displays “Physic:…”

Thank you very much for your help. I really appreciate it a lot.

<FORM NAME="contact_us" ACTION="Thankyou.asp" METHOD="POST" ID="Form1">
<p>Fields marked with an asterisks (<font color="#FF0000">*</font>) are required.</p>
<br>
<p><strong>To:</strong><br>
<select name="group_name" id="group_name" onchange="changeValue()">
<option value="generalinf" selected>General Information</option>
<option value="math">Math</option>
<option value="physic">Physic</option>
<option value="bio">Biology</option>
<option value="other">Other</option>
</select>
</p>
<p><strong><font color="#FF0000">*</font>From:</strong> (your email address)<br />
<INPUT TYPE="text" NAME="from" TABINDEX="2" SIZE="50" MAXLENGTH="100" ID="Text1">
</p>
<p><strong><font color="#FF0000">*</font>Subject:</strong><br />
<INPUT TYPE="text" NAME="subject" TABINDEX="3" SIZE="50" MAXLENGTH="100" ID="Text2">
</p>
<p>
<p><strong><font color="#FF0000">*</font>Question or Comment:</strong><br />
<!--<DIV ID="showMessage" name="showMessage">
Math: please provide the problem
</DIV>--->
<textarea name="message" cols="50" rows="10" wrap="virtual" tabindex="4" ID="Textarea1"></textarea>
</p>
<br>
<p>
<input type="submit" value="Send Message" class="button" tabindex="5" ID="Submit1" NAME="Submit1" /></p>
</FORM>
ClueLess is offline   Reply With Quote
Old 12-07-2004, 07:23 PM   PM User | #2
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
Please try the following




<script language="javascript">
<!--
mytxt=new Array()
mytxt[0]=""
mytxt[1]="Math: please provide the problem"
mytxt[2]="Physics: ..............."
mytxt[3]="Biology ---------"
mytxt[4]="Other ???????"

function changeValue(n){
document.getElementById("showMessage").innerHTML=mytxt[n]
}
//-->
</script>



<FORM NAME="contact_us" ACTION="Thankyou.asp" METHOD="POST" ID="Form1">
<p>Fields marked with an asterisks (<font color="#FF0000">*</font>) are required.</p>
<br>
<p><strong>To:</strong><br>
<select name="group_name" id="group_name" onchange="changeValue(options.selectedIndex)">
<option value="generalinf" selected>General Information</option>
<option value="math">Math</option>
<option value="physic">Physic</option>
<option value="bio">Biology</option>
<option value="other">Other</option>
</select>
</p>
<p><strong><font color="#FF0000">*</font>From:</strong> (your email address)<br />
<INPUT TYPE="text" NAME="from" TABINDEX="2" SIZE="50" MAXLENGTH="100" ID="Text1">
</p>
<p><strong><font color="#FF0000">*</font>Subject:</strong><br />
<INPUT TYPE="text" NAME="subject" TABINDEX="3" SIZE="50" MAXLENGTH="100" ID="Text2">
</p>
<p>
<p><strong><font color="#FF0000">*</font>Question or Comment:</strong><br />
<DIV ID="showMessage">&nbsp;</DIV>
<textarea name="message" cols="50" rows="10" wrap="virtual" tabindex="4" ID="Textarea1"></textarea>
</p>
<br>
<p>
<input type="submit" value="Send Message" class="button" tabindex="5" ID="Submit1" NAME="Submit1" /></p>
</FORM>
__________________
The silent one.

The most dangerous thing in the world is an idea.
The most dangerous person in the world is the one with an idea.
Mr J is offline   Reply With Quote
Old 12-07-2004, 07:32 PM   PM User | #3
Basscyst
Smokes a Lot


 
Join Date: Jul 2003
Location: CA, USA
Posts: 1,594
Thanks: 5
Thanked 20 Times in 20 Posts
Basscyst is on a distinguished road
hello,

See how this works?

Code:
<html>
<head>
<script type="text/javascript">
function showMessage(str)
{
	var msg=new Array();
	msg['physics']="physics msg";
	msg['math']="math msg";
	msg['misc']="misc. msg";
	document.getElementById('info').innerHTML=msg[str];
}
</script>
</head>
<body>
<form>
	<select onchange="showMessage(this.options[this.selectedIndex].value)">
		<option selected>Select. . .</option>
		<option value="physics">Physics</option>
		<option value="math">Math</option>
		<option value="misc">Misc</option>
	</select>
</form>
<div id="info"></div>
</body>
</html>
Edit: Heh, guess I shouldn't have got up for a minute.


Basscyst
__________________
Helping to build a bigger box. - Adam Matthews
Basscyst is offline   Reply With Quote
Old 12-07-2004, 07:51 PM   PM User | #4
ClueLess
Regular Coder

 
Join Date: Nov 2002
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
ClueLess is an unknown quantity at this point
Smile

THANK YOU VERY MUCH. YOU BOTH ARE VERY HELPFUL. YES, THEY BOTH WORK GREAT.
ClueLess is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:11 AM.


Advertisement
Log in to turn off these ads.