<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>
4 Replies - 989 Views - Last Post: 18 July 2011 - 06:51 AM
#1
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.
Replies To: Why does JSP button not work when I attach a JS function to it?
#2
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.
#3
Re: Why does JSP button not work when I attach a JS function to it?
Posted 18 July 2011 - 06:16 AM
#4
#5
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
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>
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote




|