/    Sign up×
Community /Pin to ProfileBookmark

Validating drop box

I have two drop down boxes that need to be validated separately. When the one function is called, for some strange reason I am prompted with my alert box and focus is set to the other drop down box, preventing me from updating the value chosen.

Here are the functions and code:

[CODE] <script language=”JavaScript”>
function Validate(form2)

{

if(document.form2.PegNumberDrawn.selectedIndex==0)
{

alert(“Please choose the Peg Number Drawn for this angler.”);
document.form2.PegNumberDrawn.focus();
return false;
}
return true;
else

}

</script>

<script language=”JavaScript”>

function Validate(form3)

{
if(document.form3.PegNumberDrawn_Day2.value==0)
{

alert(“Please choose the Peg Number Drawn for this angler.”);
document.form3.PegNumberDrawn_Day2.focus();
return false;
}

else
{
document.form3.submit();
}

}

</script>[/CODE]

Drop Down box:

[CODE]
<table>
<tr>
<td>
<form method=”post” action=”thepage.asp” name=”form2″>
<input type=”hidden” value=”<&#37;=RSCustomers(“CustomerId”)%>” name=”CustomerId”>
<input type=”hidden” value=”<%=FishId%>” name=”FishId”>
<input type=”hidden” value=”Second” name=”DatabaseNumber”>

<select NAME=”PegNumberDrawn” SIZE=”1″>
<option VALUE=””><%=PegNumberDrawn%>

<option VALUE=”1″>1
<option VALUE=”2″>2
<option VALUE=”3″>3
<option VALUE=”4″>4
<option VALUE=”5″>5

</select>
<input type=”BUTTON” onclick=”Validate(form2);return false;” value=”Update Peg” name=”submit1″ align=”left”>
</form>

</td>
</tr>
</table>
</form>

<table>
<tr>
<td>
<font color=”white” size=”4″><u><b>Peg Number Drawn – Day 2<b></u></font>
<br>
<form method=”post” action=”AssignPegNumberDrawnUpdate_Second.asp” name=”form3″>
<input type=”hidden” value=”Yes” name=”SecondDay_PegDraw”>
<input type=”hidden” value=”<%=RSCustomers(“CustomerId”)%>” name=”CustomerId”>
<input type=”hidden” value=”<%=FishId%>” name=”FishId_PegNumberDrawn_Day2_FishId”>
<input type=”hidden” value=”Second” name=”DatabaseNumber”>

<select NAME=”PegNumberDrawn_Day2″ SIZE=”1″>

<option VALUE=””><%=RS_PegNumberDrawn_Day2(“PegNumberDrawn_Day2″)%>

<option VALUE=”1″>1
<option VALUE=”2″>2
<option VALUE=”3″>3
<option VALUE=”4″>4
<option VALUE=”5″>5

</select>
<input type=”BUTTON” onclick=”Validate(form3);return false;” value=”Update Peg – Day 2″ name=”submit1″ align=”left”>
</form>
</td>
</tr>
</table>

[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ASPSQLVBauthorMar 31.2011 — Figured it out.

Forgot to add the button value="Submit" for each button....and used this javascript validation instead:

[CODE]<script Language="JavaScript">
function validatePegDraw_Day1(){
var selectedCombobox1=(document.form2.PegNumberDrawn.value);
if (selectedCombobox1=="-1") {
alert("Please choose the Peg Number Drawn for this angler.");
return false;
}

else
{
document.form2.submit();
</script>

<script language="JavaScript">
function validatePegDraw_Day2(){
var selectedCombobox2=(document.form3.PegNumberDrawn_Day2.value);
if (selectedCombobox2=="-1") {
alert("Please choose the Peg Number Drawn for this angler.");
return false;
}

else
{
document.form3.submit();

</script>[/CODE]
×

Success!

Help @ASPSQLVB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...