Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > anyone good with javascript?

Reply
Thread Tools

anyone good with javascript?

 
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      07-07-2005
Hi I have 3 drop down list boxes on a webform with a submit button. When the
submit button is selected if any of the dropdown listbox selected index = 0 I
want to popup a message box and not allow the submit to work. Anyhow
thinking this may require javascript.
thanks.
--
Paul G
Software engineer.
 
Reply With Quote
 
 
 
 
Phillip Ian
Guest
Posts: n/a
 
      07-07-2005
Assuming your lists are DropDownList1, 2 and 3, and your button is
btnOk...

In page_load:

btnOk.Attributes.Add("onClick", "javascript:return validateOk()")
Dim s As String = ""
s &= vbCrLf & "<script language='javascript'><!--" & vbCrLf
s &= vbTab & "function validateOk() {" & vbCrLf
s &= vbTab & vbTab & "if (document.Form1." & DropDownList1.ClientID
& ".selectedIndex == 0) { " & vbCrLf
s &= vbTab & vbTab & vbTab & "alert('Choose from the first
dropdown!');" & vbCrLf
s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
s &= vbTab & vbTab & "}" & vbCrLf
s &= vbTab & vbTab & "if (document.Form1." & DropDownList2.ClientID
& ".selectedIndex == 0) { " & vbCrLf
s &= vbTab & vbTab & vbTab & "alert('Choose from the second
dropdown!');" & vbCrLf
s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
s &= vbTab & vbTab & "}" & vbCrLf
s &= vbTab & vbTab & "if (document.Form1." & DropDownList3.ClientID
& ".selectedIndex == 0) { " & vbCrLf
s &= vbTab & vbTab & vbTab & "alert('Choose from the third
dropdown!');" & vbCrLf
s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
s &= vbTab & vbTab & "}" & vbCrLf
s &= vbTab & vbTab & "return true;" & vbCrLf
s &= vbTab & "}" & vbCrLf
s &= "--></script>" & vbCrLf
Page.RegisterClientScriptBlock("OkButtonVal", s)

You can, of course, omit a lot of the vbTab and vbCrLf stuff...I just
throw it in for readability when debugging.

 
Reply With Quote
 
 
 
 
jasonkester
Guest
Posts: n/a
 
      07-07-2005
First of all, Yikes!

What's stopping you from putting that Script block in the HTML, where
it belongs? In fact, that whole thing should be client side:

<input type="submit" onclick="return validateOk();" runat=server/>

<script>
// decode all that script above and put it here.
</script>

Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

 
Reply With Quote
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      07-07-2005
ok will give it a try thanks.
--
Paul G
Software engineer.


"Phillip Ian" wrote:

> Assuming your lists are DropDownList1, 2 and 3, and your button is
> btnOk...
>
> In page_load:
>
> btnOk.Attributes.Add("onClick", "javascript:return validateOk()")
> Dim s As String = ""
> s &= vbCrLf & "<script language='javascript'><!--" & vbCrLf
> s &= vbTab & "function validateOk() {" & vbCrLf
> s &= vbTab & vbTab & "if (document.Form1." & DropDownList1.ClientID
> & ".selectedIndex == 0) { " & vbCrLf
> s &= vbTab & vbTab & vbTab & "alert('Choose from the first
> dropdown!');" & vbCrLf
> s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
> s &= vbTab & vbTab & "}" & vbCrLf
> s &= vbTab & vbTab & "if (document.Form1." & DropDownList2.ClientID
> & ".selectedIndex == 0) { " & vbCrLf
> s &= vbTab & vbTab & vbTab & "alert('Choose from the second
> dropdown!');" & vbCrLf
> s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
> s &= vbTab & vbTab & "}" & vbCrLf
> s &= vbTab & vbTab & "if (document.Form1." & DropDownList3.ClientID
> & ".selectedIndex == 0) { " & vbCrLf
> s &= vbTab & vbTab & vbTab & "alert('Choose from the third
> dropdown!');" & vbCrLf
> s &= vbTab & vbTab & vbTab & "return false;" & vbCrLf
> s &= vbTab & vbTab & "}" & vbCrLf
> s &= vbTab & vbTab & "return true;" & vbCrLf
> s &= vbTab & "}" & vbCrLf
> s &= "--></script>" & vbCrLf
> Page.RegisterClientScriptBlock("OkButtonVal", s)
>
> You can, of course, omit a lot of the vbTab and vbCrLf stuff...I just
> throw it in for readability when debugging.
>
>

 
Reply With Quote
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      07-07-2005
yep thinking it should all be done on the client side (html)
--
Paul G
Software engineer.


"jasonkester" wrote:

> First of all, Yikes!
>
> What's stopping you from putting that Script block in the HTML, where
> it belongs? In fact, that whole thing should be client side:
>
> <input type="submit" onclick="return validateOk();" runat=server/>
>
> <script>
> // decode all that script above and put it here.
> </script>
>
> Good luck!
>
> Jason Kester
> Expat Software Consulting Services
> http://www.expatsoftware.com/
>
>

 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      07-08-2005
"Paul" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> yep thinking it should all be done on the client side (html)


Definitely.


 
Reply With Quote
 
Phillip Ian
Guest
Posts: n/a
 
      07-08-2005
My only excuse is that I work with lots of user controls...thus I need
to use .ClientID rather than the actual name of the component.

If it's all on the page, I guess no reason.

-Phil

 
Reply With Quote
 
jasonkester
Guest
Posts: n/a
 
      07-09-2005
Sounds reasonable enough. Though I'd probably still try to only spit
out as much code from the server as necessary:

Dim handleScript As String = String.Format("var boxHandle = {0};",
box.ClientID);
Page.RegisterClientScriptBlock*(handleScript) ;

<script>
function box_IndexChanged
{
var box = document.getElementByID(boxHandle);
...
}
</script>


Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone Carry Gear on Lufthansa Air? Bill? Roger? Anyone? :) MarkČ Digital Photography 34 05-20-2006 11:16 AM
Anyone who posts for Help in Here needs Intellix - Anyone providing Help Applicable Also Ditto21 Computer Support 8 02-18-2006 04:27 AM
Anyone?? Anyone at all?? JDS HTML 2 09-29-2005 07:10 PM
Anyone know anyone in Toronto Canada that will write your Mcsa Exams MonkeyMunx Microsoft Certification 17 01-05-2004 03:37 PM
Anyone? Anyone? Steve Williams Python 0 09-16-2003 03:26 AM



Advertisments