...

View Full Version : displays message depend on the item that we've selected?



ClueLess
12-07-2004, 08:08 PM
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>

Mr J
12-07-2004, 08:23 PM
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>

Basscyst
12-07-2004, 08:32 PM
hello,

See how this works?



<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>


Heh, guess I shouldn't have got up for a minute. :)

Basscyst

ClueLess
12-07-2004, 08:51 PM
THANK YOU VERY MUCH. YOU BOTH ARE VERY HELPFUL. YES, THEY BOTH WORK GREAT. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum