Advanced Search

Results 1 to 5 of 5

Thread: href submit function problem

  1. #1
    Join Date
    Nov 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile href submit function problem

    Hi
    I have a javascript function as follows in my page which
    <script language="javascript">
    function password_check()
    {
    if(document.getElementById('new_pass1').value==document.getElementById('new_pass2').value) { document.getElementById('log1').submit();
    } else{//some another activity. } }
    </script>

    This script is getting used by a button in HTML body,detailed below:
    <body>
    <form name="log" method="POST" action="<%=user_ver%>" id="log1">

    <!--<%=user_ver%> is the jsp code for the address of the servlet,which doesnot have any kind of problem -->

    <input name="new_pass1" type="password" id="new_pass1" size="50%" align="middle"><br>

    <input name="new_pass2" type="password" id="new_pass2"
    size="50%" align="middle" ><br>

    <input name="Submit" onclick="password_check()" size="50" type="button" id="Submit" value="SubmiT" align="middle">
    </form></body>

    My problem is that when I hit SubmiT button it fires an error saying that document.getElementById('log1') is null. If I chnage that piece of code in function with document.log.submit(); then it says that document.log is not defined. Could you help me in this and also to find what's going wrong in this?

  2. #2
    Join Date
    Nov 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    The above mentioned errors have received in firefox. In Internet explorer, getting the error-Object does not support this property or method.

    Please help.

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    I copied your code, when I ran it I saw no errors in firefox's error console, I did take out the "//some another activity." part though.

    Any more code that you've omitted and might be causing the problem?

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I have refined the code you've provided a bit. It seems that you are using the "ID" property on every element, which I thought unnecessary and can be avoided.

    1. Also I have noticed that in your code you've used the "size" property associated with the "password" textbox and button element incorrectly. The "size" is a property that usually used with text box elements to denote how many character can be entered into them. It doesn't represent the "width" of the element. If you want to adjust the "width" of the input elements you can use CSS like the following manner.

    Code:
    <input name="new_pass1" type="password" style="width: 150px;">
    2. I have avoided the usage of inline event handling in my code in which I've associated the event handler through JS code

    3. I have avoided the usage of deprecated "align" property from input elements. If you want to align the elements try to use CSS.

    Here is the modified JS and HTML markup

    Code:
    <script type="text/javascript">
    	function password_check(){
    		var form = document.forms['log']; //Form element
    		if(form && form.elements['new_pass1'].value === form.elements['new_pass2'].value) { 
    			form.submit();
    		} else{
    			alert('Either the form object is null or the value checking is false);
    		} 
    	}
    	
    	window.onload = function(){
    		var form = document.forms['log'];
    		form.elements['Submit'].onclick = password_check;
    	}
    </script>
    Code:
    <body>
    	<form name="log" method="POST" action="<%=user_ver%>">
    		<input name="new_pass1" type="password" size="50"><br>
    		<input name="new_pass2" type="password" size="50"><br>
    		<input name="Submit" type="button" value="SubmiT">
    	</form>
    </body>
    Hope this helps.

  5. #5
    Join Date
    Nov 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the info, One more thing which I want to know about what if I call this above discussed page in another page and then submit the page. Now I figured out that it is not the code problem actually since I am calling this page within another page and then submiting the page that is why it is producing this error.Something like:
    <html>
    <body>
    <form>

    //here calling the above page :I'm using JSP:include tag which is like another method of other languages ,for that
    </form>
    </body>
    </head>

    In this scenario, how would we make submit button to submit the page with all hidden values and other component's entries of the page?

Bookmarks

Posting Permissions

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