4 Replies - 1913 Views - Last Post: 18 July 2011 - 06:51 AM

#1 lunixer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: 29-January 10

Why does JSP button not work when I attach a JS function to it?

Posted 18 July 2011 - 05:52 AM

Hi. I am making this button in a JSP file. I am trying to make the button do two things: save changes to a profile and, when clicked, display the text "saved" below it. The former worked until I added an onlick to the button that triggers the "saved" to appear. Does anybody have any idea why this is? I have attached the code below.

 <td colspan="2" align="center">
								<button 
									class="ur_button"  
									type="submit"
									onmouseout="this.className='ur_button';"
									onmouseover="this.className='ur_buttonover';"
									onclick="showLinks('class1');return false;">
 		                        	Save Account</button> 
	                               <p/> <!-- added by Joe -->
								<!-- Script below added by Joe -->
								<script type="text/javascript">
								function showLinks(n){
								document.getElementById(n).style.display='block'
								}
								</script>
								<!-- line below added by Joe -->
								<div id="class1" style="display: none"><font color=red>Saved!</font></div>


	                      </td>



Is This A Good Question/Topic? 0
  • +

Replies To: Why does JSP button not work when I attach a JS function to it?

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Why does JSP button not work when I attach a JS function to it?

Posted 18 July 2011 - 06:11 AM

Returning false cancels the button's default operation. showLinks should be executed but the form won't be submitted.
Was This Post Helpful? 1
  • +
  • -

#3 lunixer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: 29-January 10

Re: Why does JSP button not work when I attach a JS function to it?

Posted 18 July 2011 - 06:16 AM

View Postcodeprada, on 18 July 2011 - 09:11 AM, said:

Returning false cancels the button's default operation. showLinks should be executed but the form won't be submitted.


What would I return if I wanted the default operation to stay intact?
Was This Post Helpful? 0
  • +
  • -

#4 lunixer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: 29-January 10

Re: Why does JSP button not work when I attach a JS function to it?

Posted 18 July 2011 - 06:28 AM

View Postlunixer, on 18 July 2011 - 09:16 AM, said:

View Postcodeprada, on 18 July 2011 - 09:11 AM, said:

Returning false cancels the button's default operation. showLinks should be executed but the form won't be submitted.


What would I return if I wanted the default operation to stay intact?


Never mind. Stupid question. Ha ha. Return true.
Was This Post Helpful? 0
  • +
  • -

#5 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Why does JSP button not work when I attach a JS function to it?

Posted 18 July 2011 - 06:51 AM

You don't have to return anything.

It's just like validating a form before submitting it.
Example
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function validate(form)
{
	//no need to return true 
	if(form.test.value < 0)
		return false; //if value is less than zer0 return false canceling submission
}
</script>
</head>
<body>
<form onsubmit="return validate(this)" action="url.php">
  <input type="text" name="test" />
  <input type="submit" value="Submit" />
</form>
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1