Current location: Hot Scripts Forums » General Web Coding » JavaScript » display selected value in drop down list


display selected value in drop down list

Reply
  #1 (permalink)  
Old 04-01-04, 10:17 PM
angela angela is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
display selected value in drop down list

hello!
The script below does validation. But i would like to retain the value if a value is selected.

<script language="javascript">
function validateForm(form)
{
if(form.partnerlist.value == "" && form.Mth.value == "" && form.Yr.value == "")
{
alert("Please select all required fields.");
return false;
}
else if(form.partnerlist.value == "" && form.Mth.value == "")
{
alert("Please select Partner and Month.");
return false;
}
else if(form.partnerlist.value == "" && form.Yr.value == "")
{
alert("Please select Partner and Year.");
return false;
}
else if(form.partnerlist.value == "" )
{
alert("Please select Partner.");
return false;
}
else if(form.Mth.value == "" && form.Yr.value == "")
{
alert("Please select Month and Year.");
return false;
}
else if(form.Yr.value == "")
{
alert("Please select Year.");
return false;
}
else if(form.Mth.value == "")
{
alert("Please select Month.");
return false;
}
else
{
document.forms.view_form.thestatus.value = "ok";
}
}

function writeMonthOptions()
{
var Months = new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December")

for (monthCounter = 0; monthCounter < Months.length; monthCounter++)
{
document.write('<OPTION value=' + (monthCounter+1) + '>' + Months[monthCounter]);
}
}
</script>


eg.
(form.partnerlist.value == "" && form.Yr.value == "")
since month is selected...i would like to keep the selected value and display in the drop down list. but how do i do that? do i make use of session to store the selected value?

mth = request.QueryString("Mth")
yr = request.QueryString("Yr")

<select name="Mth" class="formlist">
<option></option>
<SCRIPT LANGUAGE=JavaScript>
writeMonthOptions();
</SCRIPT>
</select>
Reply With Quote
  #2 (permalink)  
Old 04-02-04, 08:43 AM
tarakshah tarakshah is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Dropdown value

Hii

I think that when u write return false then other values which are filled are remained as it is. so there is no need to write any code..

or u use the if condition to check

if (form.Mth.value == monthcounter)
{
document.write('<OPTION Selected value=' + (monthCounter+1) + '>' + Months[monthCounter]);
else
document.write('<OPTION value=' + (monthCounter+1) + '>' + Months[monthCounter]);

Is it what u need or do specify clearly..

Tarak
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Formmail Script Fix - Cant display multiple list selections.. zamen PHP 3 05-02-04 09:59 AM
month drop down list angela JavaScript 2 03-31-04 02:33 AM
Execute javascript function based on selected dropdown list value. TKOEHN5751 JavaScript 2 03-14-04 12:13 AM
drop down menu problem !!! nurqeen PHP 1 02-08-04 08:07 PM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM


All times are GMT -5. The time now is 02:14 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.