Results 1 to 3 of 3

Thread: [RESOLVED] Whats wrong with this code

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Resolved [RESOLVED] Whats wrong with this code

    Dear all.

    I have wrote the following code but its not woring properly. Please suggest what to do

    Code:
    <html>
    
    
    
    <Body>
    
    <Center>
    
    <table width="50%" border="1">
    	<td><input type="button" name="cmdNew" value="New Record"/></td>
    	<td><input type="button" name="cmdSave" value="Save Record" onclick="GoSave()"></td>
    	<td><input type="button" value="Reset Values" onclick="goReset"/></td>
    	<td><input type="button" name="cmdDelete" value="Delete Record"/></td>
    	<td><input type="button" name="cmdBack" value="Back to Home" onClick="GoMain()"/></td>
    </table>
    
    
    <table width="100%" border="0" bgcolor="#0099FF">
      <tr>
        <th height="28" scope="col"><span class="style1">NEW CIO PROFILE</span></th>
      </tr>
    </table>
    
    
    
    <BR><BR><BR><BR><BR><BR>
    
    <Form method="post" action="NewCioProfile.asp">
    
    <script language="VBScript">
    	Sub GoMain()
    		<% response.Redirect("main.asp") %>
    	End Sub
    
    	 Sub GoSave()
    		if mcioid="" then
    			msgbox "23323"
    		end if
    	 End Sub
    
    	 Sub GoReset()
    		cioid.Value=""
    		cioname.Value=""
    		supername.Value=""	
    	 End Sub
    
    </script>
    
    
    <table Width="50%">
    	<tr><td></td></tr>
    
    	<Tr>
    		<td>CIO ID</td><td><input type ="text" name="CIOId" size="10" maxlength="10"></td>
    	</tr>
    
    	<tr>
    		<td>CIO Name</td><td><input type ="text" name="CIOName"></td>
    	</tr>
    
    	<tr>
    		<td>Spervisor Name</td><td><input type ="text" name="SuperName"></td>
    	</tr>
    	
    	<tr>	</tr>
    
    </Table>
    
    </Form>
    </Center>
    
    
    </Body>
    </html>

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Whats wrong with this code

    VBScript is used in several different ways; it looks like you've got two of those ways mixed up here.

    VBScript Embedded in HTML
    This is when you have a <script> element with VBScript code in it. This script runs on the client-side (after the web page has been fully loaded in the browser), and only works in IE.

    VBScript in ASP
    ASP is a scripting framework that allows the use of VBScript as its language. This is when you have <&#37;%> tags with VBScript in them. This script runs server-side (before the web page is loaded), and works in any browser.

    You can't functionally mix the two of them, as you've done here:
    Code:
    Sub GoMain()
      <% response.Redirect("main.asp") %>
    End Sub
    When an ASP page loads, all of the ASP gets processed first - so if you put this page on an ASP-supporting server and viewed it in a browser, it would redirect to "main.asp" before this page loads.

    So, your code could be fixed to work with either choice. For either method, <input> elements always need to exist within a <form> element. So take everything that is between your <center> tag and your <form> tag, and move it below the <form> tag. You can also get rid of all the "onclick" attributes on your <input>s, because none of these are useful for your code. For your "Reset Values" <input>, simply change the "type" to "reset" - you don't have to write your own reset function, there is already a default behavior for this in your browser.

    For VBScript in HTML, the way that you write a function that occurs when clicking an input is to write:
    Code:
    sub elementName_OnClick()
    So for instance, change your "Sub GoSave()" to "Sub cmdSave_OnClick()" and it will work (please remove "<% response.Redirect("main.asp") %>" because that is invalid here). The same goes for "Sub GoMain()" - rewrite it as "sub cmdBack_OnClick()". For redirecting, you've tried to use the ASP method; change to:
    Code:
    Sub cmdBack_OnClick()
      location.href="main.asp"
    End Sub
    If you search for sample code, make sure it's in the context of <script> tags; if you see it inside of <%%> tags, then it won't work for HTML-VBScript.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Whats wrong with this code

    Dear SambaNeko,
    Thanks for helping in such a great way. I really apprecite it. My issue is resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width