Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto selecting options in a form

Status
Not open for further replies.

irate

Programmer
Joined
Jan 29, 2001
Messages
92
Location
GB
This is my code:

<script>
function colourformat(theform,colourformat,prompttext)
{
inserttext = prompt(&quot;\n<font style=\&quot;color:&quot;+colourformat+&quot;;\&quot;>xxx</font>&quot;,prompttext);
theform.about.value += &quot;<font style=\&quot;color:&quot;+colourformat+&quot;;\&quot;>&quot;+inserttext+&quot;</font>&quot;;
}
</script>
<form action=&quot;admin.asp&quot; method=&quot;post&quot;>
<select name=&quot;colour&quot; onchange=&quot;colourformat(this.form,this.options[this.selectedIndex].value,'Type the text you want change the colour of.')&quot;>
<option value=&quot;black&quot; style=&quot;color:black&quot;>black</option>
<option value=&quot;skyblue&quot; style=&quot;color:skyblue&quot;>sky blue</option>
<option value=&quot;royalblue&quot; style=&quot;color:royalblue&quot;>royal blue</option>
<option value=&quot;blue&quot; style=&quot;color:blue&quot;>blue</option>
<option value=&quot;darkblue&quot; style=&quot;color:darkblue&quot;>dark-blue</option>
<option value=&quot;orange&quot; style=&quot;color:orange&quot;>orange</option>
<option value=&quot;orangered&quot; style=&quot;color:orangered&quot;>orange-red</option>
<option value=&quot;crimson&quot; style=&quot;color:crimson&quot;>crimson</option>
<option value=&quot;red&quot; style=&quot;color:red&quot;>red</option>
<option value=&quot;firebrick&quot; style=&quot;color:firebrick&quot;>firebrick</option>
<option value=&quot;darkred&quot; style=&quot;color:darkred&quot;>dark red</option>
<option value=&quot;green&quot; style=&quot;color:green&quot;>green</option>
<option value=&quot;limegreen&quot; style=&quot;color:limegreen&quot;>limegreen</option>
<option value=&quot;seagreen&quot; style=&quot;color:seagreen&quot;>sea-green</option>
<option value=&quot;deeppink&quot; style=&quot;color:deeppink&quot;>deeppink</option>
<option value=&quot;tomato&quot; style=&quot;color:tomato&quot;>tomato</option>
<option value=&quot;coral&quot; style=&quot;color:coral&quot;>coral</option>
<option value=&quot;purple&quot; style=&quot;color:purple&quot;>purple</option>
<option value=&quot;indigo&quot; style=&quot;color:indigo&quot;>indigo</option>
<option value=&quot;burlywood&quot; style=&quot;color:burlywood&quot;>burlywood</option>
<option value=&quot;sandybrown&quot; style=&quot;color:sandybrown&quot;>sandy brown</option>
<option value=&quot;sienna&quot; style=&quot;color:sienna&quot;>sienna</option>
<option value=&quot;chocolate&quot; style=&quot;color:chocolate&quot;>chocolate</option>
<option value=&quot;teal&quot; style=&quot;color:teal&quot;>teal</option>
<option value=&quot;silver&quot; style=&quot;color:silver&quot;>silver</option>
</select>
<br>
<textarea name=&quot;about&quot; cols=&quot;75&quot; rows=&quot;15&quot;></textarea>
</form>


When the user selects a colour other than black there is a dialogue that asks for text. Then when they press ok it puts in the HTML and the text in to the textarea in the form.

Now: I what i want to do is when the user clicks ok on the dialogue the select form item returns to the black option and the form focus is set to the end of the textarea...

any ideas?
 
function colourformat(theform,colourformat,prompttext)
{
inserttext = prompt(&quot;\n<span style=\&quot;color:&quot;+colourformat+&quot;;\&quot;>xxx</span>&quot;,prompttext);
theform.about.value += &quot;<span style=\&quot;color:&quot;+colourformat+&quot;;\&quot;>&quot;+inserttext+&quot;</span>&quot;;

theform.colour.options[0].selected = true;
theform.about.focus();
}

The last line set the 1st option to &quot;selected&quot; state.
As for tyour second request - all I can tell that you cannot specity where exactly the cursor will appear in textarea. It depends on default browser settings that you can't change. Some browsers set the cursor at the beginning of textarea, some - at the end of it.

Also, I slightly modified your code: replaced all <font> tags with <span> tags. Make your code look more &quot;modern&quot; and professional. The <font> tag is outdated and not recommended to use according new standards. Using <span> will not change anything in your page dispay.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top