|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Button Value not updating when Changed
Hi,
I want to get users to verify their email addresses before submitting my form using the following code [the alerts have been added to help debugging]: Code:
<script language="JavaScript" type="text/JavaScript">
function presssave(Buttjs, Emailjs) {
alert(Buttjs.value);
Buttjs.value='Pressed';
alert(Buttjs.value);
var x=window.confirm("You will use your email address to login.\n\nPlease check it carefully before carrying on. \n\n "+Emailjs.value+"\n\nIs this correct ?");
if (x) {
document.UserDetails.submit();
}else{
Emailjs.focus()
}
}
</script>
This works apart from setting the value of the button to 'Pressed' while the confirm box is shown. I have another page and form where this seems to work fine. I have added the alerts to try and track what is going on. They tell me that the value of the button has been changed to 'Pressed', but it still shows 'Save' as it did to start with. What have I done wrong? I have spent ages trying to work it out without success. Any ideas gratefully receieved! ![]() |
|
#2
|
||||
|
||||
|
I didn't change a thing, but made your example bigger for my own testing...
Code:
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function presssave(Buttjs, Emailjs) {
alert(Buttjs.value);
Buttjs.value='Pressed';
alert(Buttjs.value);
var x=window.confirm("You will use your email address to login.\n\nPlease check it carefully before carrying on. \n\n "+Emailjs.value+"\n\nIs this correct ?");
if (x) {
//document.UserDetails.submit();
alert("Submit");
}else{
Emailjs.focus()
}
}
</script>
</head>
<body>
<input type="text" id="email" />
<input type="button" name="button1" value="Save" onclick="javascript:presssave(this, document.getElementById('email'));" />
</body>
</html>
Testing in Firefox 1.0.7, IE6, and Opera 8.5... it seems to work... Again, I didn't change a thing =) Let me know if my test page here works for you... There may be something else funky going on with your original page. |
|
#3
|
|||
|
|||
|
Thanks MadCowDzz. I haven't tried it yet, but will over the next couple of days.
For some reason on my page, the button is not being posted at all (IE or Netscape, haven't tried FireFox). I was checking for this POST in PHP to decide whether to save new or update an existing MySQL user record. I have now changed the way this works so am over the urgency of the problem - but I don't like leaving things like this without understanding what's going on! Be back to you soon. |
|
#4
|
||||
|
||||
|
As I said, I didn't change your code one bit.
It may have to do with the placement of your javascript blocks? Let us know if my example above works for you.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
|
#5
|
|||
|
|||
|
From what I can surmise from W3C and WDG , input type=button does not get posted, but is only useful for client-side scripting.
|
|
#6
|
||||
|
||||
|
Squeegee, you're absolutely correct, and it's definitely worth noting.
The button in the code above doesn't seem to be used for submitting a form but rather triggering the Javascript. This is a push button serving it's primary purpose =) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Button Value not updating when Changed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|